--
--

-- Started on 2012-10-25 17:05:02

SET escape_string_warning = off;

--
-- TOC entry 6 (class 2615 OID 25354)
-- Name: kc; Type: SCHEMA; Schema: -; Owner: postgres
--

CREATE SCHEMA kc;


ALTER SCHEMA kc OWNER TO postgres;


--
-- TOC entry 166 (class 1255 OID 25355)
-- Dependencies: 6
-- Name: renew_kc_db(); Type: FUNCTION; Schema: kc; Owner: postgres
--

CREATE FUNCTION renew_kc_db() RETURNS void
    LANGUAGE sql
    AS $$ALTER SEQUENCE kc.extracted_id_seq RESTART 1;
ALTER SEQUENCE kc.predicate_id_seq RESTART 1;
ALTER SEQUENCE kc.term_eq_id_seq RESTART 1;
ALTER SEQUENCE kc.type_id_seq RESTART 1;

DELETE FROM kc.document;
DELETE FROM kc.extracted;
DELETE FROM kc.predicate;
DELETE FROM kc.term_eq;
DELETE FROM kc.type;
DELETE FROM kc.kc;
DELETE FROM kc.maptable;
$$;


ALTER FUNCTION kc.renew_kc_db() OWNER TO postgres;



--
-- TOC entry 141 (class 1259 OID 25356)
-- Dependencies: 1809 6
-- Name: document; Type: TABLE; Schema: kc; Owner: postgres; Tablespace: 
--

CREATE TABLE document (
    url character varying NOT NULL,
    uri character varying,
    local boolean DEFAULT true
);


ALTER TABLE kc.document OWNER TO postgres;

--
-- TOC entry 143 (class 1259 OID 25365)
-- Dependencies: 1810 6
-- Name: extracted; Type: TABLE; Schema: kc; Owner: postgres; Tablespace: 
--

CREATE TABLE extracted (
    document character varying NOT NULL,
    kc character varying NOT NULL,
    weight double precision DEFAULT 1,
    code integer,
    note character varying,
    id integer NOT NULL
);


ALTER TABLE kc.extracted OWNER TO postgres;

--
-- TOC entry 142 (class 1259 OID 25363)
-- Dependencies: 143 6
-- Name: extracted_id_seq; Type: SEQUENCE; Schema: kc; Owner: postgres
--

CREATE SEQUENCE extracted_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE kc.extracted_id_seq OWNER TO postgres;

--
-- TOC entry 1857 (class 0 OID 0)
-- Dependencies: 142
-- Name: extracted_id_seq; Type: SEQUENCE OWNED BY; Schema: kc; Owner: postgres
--

ALTER SEQUENCE extracted_id_seq OWNED BY extracted.id;


--
-- TOC entry 144 (class 1259 OID 25373)
-- Dependencies: 1812 1813 6
-- Name: kc; Type: TABLE; Schema: kc; Owner: postgres; Tablespace: 
--

CREATE TABLE kc (
    rdf_id character varying NOT NULL,
    name character varying,
    global boolean DEFAULT false,
    term_equipment text,
    type character varying(1),
    CONSTRAINT kc_type_check CHECK (((((type)::text = 'C'::text) OR ((type)::text = 'P'::text)) OR ((type)::text = 'I'::text)))
);


ALTER TABLE kc.kc OWNER TO postgres;

--
-- TOC entry 145 (class 1259 OID 25381)
-- Dependencies: 6
-- Name: maptable; Type: TABLE; Schema: kc; Owner: postgres; Tablespace: 
--

CREATE TABLE maptable (
    global integer NOT NULL,
    simple integer NOT NULL
);


ALTER TABLE kc.maptable OWNER TO postgres;

--
-- TOC entry 147 (class 1259 OID 25386)
-- Dependencies: 6
-- Name: predicate; Type: TABLE; Schema: kc; Owner: postgres; Tablespace: 
--

CREATE TABLE predicate (
    id integer NOT NULL,
    belong_kc character varying,
    p1 character varying,
    pn character varying,
    value character varying,
    path_length integer,
    value_length integer,
    value_type character varying,
    value_kc character varying,
    confidence double precision
);


ALTER TABLE kc.predicate OWNER TO postgres;

--
-- TOC entry 146 (class 1259 OID 25384)
-- Dependencies: 6 147
-- Name: predicate_id_seq; Type: SEQUENCE; Schema: kc; Owner: postgres
--

CREATE SEQUENCE predicate_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE kc.predicate_id_seq OWNER TO postgres;

--
-- TOC entry 1858 (class 0 OID 0)
-- Dependencies: 146
-- Name: predicate_id_seq; Type: SEQUENCE OWNED BY; Schema: kc; Owner: postgres
--

ALTER SEQUENCE predicate_id_seq OWNED BY predicate.id;


--
-- TOC entry 149 (class 1259 OID 25395)
-- Dependencies: 1815 6
-- Name: term_eq; Type: TABLE; Schema: kc; Owner: postgres; Tablespace: 
--

CREATE TABLE term_eq (
    term character varying NOT NULL,
    kc character varying NOT NULL,
    relevance double precision,
    frequency integer DEFAULT 1,
    id integer NOT NULL
);


ALTER TABLE kc.term_eq OWNER TO postgres;

--
-- TOC entry 148 (class 1259 OID 25393)
-- Dependencies: 149 6
-- Name: term_eq_id_seq; Type: SEQUENCE; Schema: kc; Owner: postgres
--

CREATE SEQUENCE term_eq_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE kc.term_eq_id_seq OWNER TO postgres;

--
-- TOC entry 1859 (class 0 OID 0)
-- Dependencies: 148
-- Name: term_eq_id_seq; Type: SEQUENCE OWNED BY; Schema: kc; Owner: postgres
--

ALTER SEQUENCE term_eq_id_seq OWNED BY term_eq.id;


--
-- TOC entry 153 (class 1259 OID 25491)
-- Dependencies: 6
-- Name: term_form; Type: TABLE; Schema: kc; Owner: postgres; Tablespace: 
--

CREATE TABLE term_form (
    id integer NOT NULL,
    term integer,
    transf_name character varying NOT NULL,
    transf_value character varying NOT NULL
);


ALTER TABLE kc.term_form OWNER TO postgres;

--
-- TOC entry 152 (class 1259 OID 25489)
-- Dependencies: 153 6
-- Name: term_form_id_seq; Type: SEQUENCE; Schema: kc; Owner: postgres
--

CREATE SEQUENCE term_form_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE kc.term_form_id_seq OWNER TO postgres;

--
-- TOC entry 1860 (class 0 OID 0)
-- Dependencies: 152
-- Name: term_form_id_seq; Type: SEQUENCE OWNED BY; Schema: kc; Owner: postgres
--

ALTER SEQUENCE term_form_id_seq OWNED BY term_form.id;


--
-- TOC entry 151 (class 1259 OID 25405)
-- Dependencies: 1817 6
-- Name: type; Type: TABLE; Schema: kc; Owner: postgres; Tablespace: 
--

CREATE TABLE type (
    class character varying NOT NULL,
    instance character varying NOT NULL,
    is_type boolean DEFAULT true,
    id integer NOT NULL
);


ALTER TABLE kc.type OWNER TO postgres;

--
-- TOC entry 150 (class 1259 OID 25403)
-- Dependencies: 6 151
-- Name: type_id_seq; Type: SEQUENCE; Schema: kc; Owner: postgres
--

CREATE SEQUENCE type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE kc.type_id_seq OWNER TO postgres;

--
-- TOC entry 1861 (class 0 OID 0)
-- Dependencies: 150
-- Name: type_id_seq; Type: SEQUENCE OWNED BY; Schema: kc; Owner: postgres
--

ALTER SEQUENCE type_id_seq OWNED BY type.id;


--
-- TOC entry 1811 (class 2604 OID 25369)
-- Dependencies: 142 143 143
-- Name: id; Type: DEFAULT; Schema: kc; Owner: postgres
--

ALTER TABLE extracted ALTER COLUMN id SET DEFAULT nextval('extracted_id_seq'::regclass);


--
-- TOC entry 1814 (class 2604 OID 25389)
-- Dependencies: 146 147 147
-- Name: id; Type: DEFAULT; Schema: kc; Owner: postgres
--

ALTER TABLE predicate ALTER COLUMN id SET DEFAULT nextval('predicate_id_seq'::regclass);


--
-- TOC entry 1816 (class 2604 OID 25399)
-- Dependencies: 148 149 149
-- Name: id; Type: DEFAULT; Schema: kc; Owner: postgres
--

ALTER TABLE term_eq ALTER COLUMN id SET DEFAULT nextval('term_eq_id_seq'::regclass);


--
-- TOC entry 1819 (class 2604 OID 25494)
-- Dependencies: 153 152 153
-- Name: id; Type: DEFAULT; Schema: kc; Owner: postgres
--

ALTER TABLE term_form ALTER COLUMN id SET DEFAULT nextval('term_form_id_seq'::regclass);


--
-- TOC entry 1818 (class 2604 OID 25409)
-- Dependencies: 150 151 151
-- Name: id; Type: DEFAULT; Schema: kc; Owner: postgres
--

ALTER TABLE type ALTER COLUMN id SET DEFAULT nextval('type_id_seq'::regclass);


--
-- TOC entry 1821 (class 2606 OID 25414)
-- Dependencies: 141 141
-- Name: document_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY document
    ADD CONSTRAINT document_pkey PRIMARY KEY (url);


--
-- TOC entry 1823 (class 2606 OID 25416)
-- Dependencies: 143 143
-- Name: extracted_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY extracted
    ADD CONSTRAINT extracted_pkey PRIMARY KEY (id);


--
-- TOC entry 1825 (class 2606 OID 25418)
-- Dependencies: 143 143 143
-- Name: extracted_unique_doc_kc; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY extracted
    ADD CONSTRAINT extracted_unique_doc_kc UNIQUE (document, kc);


--
-- TOC entry 1827 (class 2606 OID 25420)
-- Dependencies: 144 144
-- Name: kc_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY kc
    ADD CONSTRAINT kc_pkey PRIMARY KEY (rdf_id);


--
-- TOC entry 1829 (class 2606 OID 25422)
-- Dependencies: 145 145 145
-- Name: maptable_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY maptable
    ADD CONSTRAINT maptable_pkey PRIMARY KEY (global, simple);


--
-- TOC entry 1831 (class 2606 OID 25424)
-- Dependencies: 147 147
-- Name: predicate_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY predicate
    ADD CONSTRAINT predicate_pkey PRIMARY KEY (id);


--
-- TOC entry 1833 (class 2606 OID 25426)
-- Dependencies: 149 149
-- Name: term_eq_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY term_eq
    ADD CONSTRAINT term_eq_pkey PRIMARY KEY (id);


--
-- TOC entry 1835 (class 2606 OID 25428)
-- Dependencies: 149 149 149
-- Name: term_eq_term_kc_unique; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY term_eq
    ADD CONSTRAINT term_eq_term_kc_unique UNIQUE (term, kc);


--
-- TOC entry 1842 (class 2606 OID 25499)
-- Dependencies: 153 153
-- Name: term_form_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY term_form
    ADD CONSTRAINT term_form_pkey PRIMARY KEY (id);


--
-- TOC entry 1838 (class 2606 OID 25430)
-- Dependencies: 151 151 151
-- Name: type_class_instance_unique; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY type
    ADD CONSTRAINT type_class_instance_unique UNIQUE (class, instance);


--
-- TOC entry 1840 (class 2606 OID 25432)
-- Dependencies: 151 151
-- Name: type_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY type
    ADD CONSTRAINT type_pkey PRIMARY KEY (id);


--
-- TOC entry 1836 (class 1259 OID 25433)
-- Dependencies: 151 151
-- Name: class_instance_index; Type: INDEX; Schema: kc; Owner: postgres; Tablespace: 
--

CREATE INDEX class_instance_index ON type USING btree (class, instance);


--
-- TOC entry 1843 (class 2606 OID 25434)
-- Dependencies: 1820 141 143
-- Name: extracted_document_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY extracted
    ADD CONSTRAINT extracted_document_fkey FOREIGN KEY (document) REFERENCES document(url) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1844 (class 2606 OID 25439)
-- Dependencies: 143 144 1826
-- Name: extracted_kc_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY extracted
    ADD CONSTRAINT extracted_kc_fkey FOREIGN KEY (kc) REFERENCES kc(rdf_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1845 (class 2606 OID 25444)
-- Dependencies: 147 1830 145
-- Name: maptable_global_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY maptable
    ADD CONSTRAINT maptable_global_fkey FOREIGN KEY (global) REFERENCES predicate(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1846 (class 2606 OID 25449)
-- Dependencies: 147 145 1830
-- Name: maptable_simple_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY maptable
    ADD CONSTRAINT maptable_simple_fkey FOREIGN KEY (simple) REFERENCES predicate(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1847 (class 2606 OID 25454)
-- Dependencies: 144 147 1826
-- Name: predicate_belong_kc_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY predicate
    ADD CONSTRAINT predicate_belong_kc_fkey FOREIGN KEY (belong_kc) REFERENCES kc(rdf_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1848 (class 2606 OID 25459)
-- Dependencies: 144 147 1826
-- Name: predicate_p1_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY predicate
    ADD CONSTRAINT predicate_p1_fkey FOREIGN KEY (p1) REFERENCES kc(rdf_id) ON UPDATE CASCADE;


--
-- TOC entry 1849 (class 2606 OID 25464)
-- Dependencies: 1826 144 147
-- Name: predicate_pn_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY predicate
    ADD CONSTRAINT predicate_pn_fkey FOREIGN KEY (pn) REFERENCES kc(rdf_id) ON UPDATE CASCADE;


--
-- TOC entry 1850 (class 2606 OID 25469)
-- Dependencies: 1826 147 144
-- Name: predicate_value_kc_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY predicate
    ADD CONSTRAINT predicate_value_kc_fkey FOREIGN KEY (value_kc) REFERENCES kc(rdf_id) ON UPDATE CASCADE;


--
-- TOC entry 1851 (class 2606 OID 25474)
-- Dependencies: 1826 149 144
-- Name: term_eq_kc_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY term_eq
    ADD CONSTRAINT term_eq_kc_fkey FOREIGN KEY (kc) REFERENCES kc(rdf_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1854 (class 2606 OID 25500)
-- Dependencies: 1832 153 149
-- Name: term_form_id_term_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY term_form
    ADD CONSTRAINT term_form_id_term_fkey FOREIGN KEY (term) REFERENCES term_eq(id);


--
-- TOC entry 1852 (class 2606 OID 25479)
-- Dependencies: 1826 144 151
-- Name: type_class_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY type
    ADD CONSTRAINT type_class_fkey FOREIGN KEY (class) REFERENCES kc(rdf_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 1853 (class 2606 OID 25484)
-- Dependencies: 1826 151 144
-- Name: type_instance_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: postgres
--

ALTER TABLE ONLY type
    ADD CONSTRAINT type_instance_fkey FOREIGN KEY (instance) REFERENCES kc(rdf_id) ON UPDATE CASCADE ON DELETE CASCADE;


-- Completed on 2012-10-25 17:05:02

--
--

