--
--

-- Started on 2013-02-05 17:07:24

SET escape_string_warning = off;

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

CREATE SCHEMA kc;



--
-- TOC entry 188 (class 1255 OID 36649)
-- Dependencies: 6
-- Name: renew_kc_db(); Type: FUNCTION; Schema: kc; Owner: -
--

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_form;
DELETE FROM kc.term_eq;
DELETE FROM kc.type;
DELETE FROM kc.kc;
DELETE FROM kc.maptable;
$$;




--
-- TOC entry 154 (class 1259 OID 36650)
-- Dependencies: 1869 6
-- Name: document; Type: TABLE; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 155 (class 1259 OID 36657)
-- Dependencies: 1870 6
-- Name: extracted; Type: TABLE; Schema: kc; Owner: -; 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
);


--
-- TOC entry 156 (class 1259 OID 36664)
-- Dependencies: 155 6
-- Name: extracted_id_seq; Type: SEQUENCE; Schema: kc; Owner: -
--

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


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

ALTER SEQUENCE extracted_id_seq OWNED BY extracted.id;


--
-- TOC entry 157 (class 1259 OID 36666)
-- Dependencies: 1872 1873 6
-- Name: kc; Type: TABLE; Schema: kc; Owner: -; 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)))
);


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

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


--
-- TOC entry 159 (class 1259 OID 36677)
-- Dependencies: 6
-- Name: predicate; Type: TABLE; Schema: kc; Owner: -; 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,
    value_text text
);


--
-- TOC entry 160 (class 1259 OID 36683)
-- Dependencies: 6 159
-- Name: predicate_id_seq; Type: SEQUENCE; Schema: kc; Owner: -
--

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


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

ALTER SEQUENCE predicate_id_seq OWNED BY predicate.id;


--
-- TOC entry 161 (class 1259 OID 36685)
-- Dependencies: 1875 6
-- Name: term_eq; Type: TABLE; Schema: kc; Owner: -; 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
);


--
-- TOC entry 162 (class 1259 OID 36692)
-- Dependencies: 161 6
-- Name: term_eq_id_seq; Type: SEQUENCE; Schema: kc; Owner: -
--

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


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

ALTER SEQUENCE term_eq_id_seq OWNED BY term_eq.id;


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

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


--
-- TOC entry 164 (class 1259 OID 36700)
-- Dependencies: 6 163
-- Name: term_form_id_seq; Type: SEQUENCE; Schema: kc; Owner: -
--

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


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

ALTER SEQUENCE term_form_id_seq OWNED BY term_form.id;


--
-- TOC entry 165 (class 1259 OID 36702)
-- Dependencies: 1878 6
-- Name: type; Type: TABLE; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 166 (class 1259 OID 36709)
-- Dependencies: 6 165
-- Name: type_id_seq; Type: SEQUENCE; Schema: kc; Owner: -
--

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


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

ALTER SEQUENCE type_id_seq OWNED BY type.id;


--
-- TOC entry 1871 (class 2604 OID 36711)
-- Dependencies: 156 155
-- Name: id; Type: DEFAULT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1874 (class 2604 OID 36712)
-- Dependencies: 160 159
-- Name: id; Type: DEFAULT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1876 (class 2604 OID 36713)
-- Dependencies: 162 161
-- Name: id; Type: DEFAULT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1877 (class 2604 OID 36714)
-- Dependencies: 164 163
-- Name: id; Type: DEFAULT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1879 (class 2604 OID 36715)
-- Dependencies: 166 165
-- Name: id; Type: DEFAULT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1881 (class 2606 OID 36717)
-- Dependencies: 154 154
-- Name: document_pkey; Type: CONSTRAINT; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1883 (class 2606 OID 36719)
-- Dependencies: 155 155
-- Name: extracted_pkey; Type: CONSTRAINT; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1885 (class 2606 OID 36721)
-- Dependencies: 155 155 155
-- Name: extracted_unique_doc_kc; Type: CONSTRAINT; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1887 (class 2606 OID 36723)
-- Dependencies: 157 157
-- Name: kc_pkey; Type: CONSTRAINT; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1889 (class 2606 OID 36725)
-- Dependencies: 158 158 158
-- Name: maptable_pkey; Type: CONSTRAINT; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1891 (class 2606 OID 36727)
-- Dependencies: 159 159
-- Name: predicate_pkey; Type: CONSTRAINT; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1893 (class 2606 OID 36729)
-- Dependencies: 161 161
-- Name: term_eq_pkey; Type: CONSTRAINT; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1895 (class 2606 OID 36731)
-- Dependencies: 161 161 161
-- Name: term_eq_term_kc_unique; Type: CONSTRAINT; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1897 (class 2606 OID 36733)
-- Dependencies: 163 163
-- Name: term_form_pkey; Type: CONSTRAINT; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1900 (class 2606 OID 36735)
-- Dependencies: 165 165 165
-- Name: type_class_instance_unique; Type: CONSTRAINT; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1902 (class 2606 OID 36737)
-- Dependencies: 165 165
-- Name: type_pkey; Type: CONSTRAINT; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1898 (class 1259 OID 36738)
-- Dependencies: 165 165
-- Name: class_instance_index; Type: INDEX; Schema: kc; Owner: -; Tablespace: 
--

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


--
-- TOC entry 1903 (class 2606 OID 36739)
-- Dependencies: 155 1880 154
-- Name: extracted_document_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1904 (class 2606 OID 36744)
-- Dependencies: 155 1886 157
-- Name: extracted_kc_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1905 (class 2606 OID 36749)
-- Dependencies: 1890 159 158
-- Name: maptable_global_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1906 (class 2606 OID 36754)
-- Dependencies: 158 1890 159
-- Name: maptable_simple_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1907 (class 2606 OID 36759)
-- Dependencies: 157 1886 159
-- Name: predicate_belong_kc_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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 1908 (class 2606 OID 36764)
-- Dependencies: 1886 159 157
-- Name: predicate_p1_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1909 (class 2606 OID 36769)
-- Dependencies: 1886 159 157
-- Name: predicate_pn_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1910 (class 2606 OID 36774)
-- Dependencies: 159 157 1886
-- Name: predicate_value_kc_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1911 (class 2606 OID 36779)
-- Dependencies: 1886 157 161
-- Name: term_eq_kc_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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 1912 (class 2606 OID 36784)
-- Dependencies: 163 1892 161
-- Name: term_form_id_term_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1913 (class 2606 OID 36789)
-- Dependencies: 165 1886 157
-- Name: type_class_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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


--
-- TOC entry 1914 (class 2606 OID 36794)
-- Dependencies: 157 1886 165
-- Name: type_instance_fkey; Type: FK CONSTRAINT; Schema: kc; Owner: -
--

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


-- Completed on 2013-02-05 17:07:25

--
--

