--
--

-- Started on 2012-06-07 19:58:28

SET escape_string_warning = off;

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

CREATE SCHEMA kc;


ALTER SCHEMA kc OWNER TO postgres;


--
-- TOC entry 174 (class 1255 OID 19935)
-- Dependencies: 5
-- 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 19936)
-- Dependencies: 1835 5
-- 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 142 (class 1259 OID 19943)
-- Dependencies: 1836 5
-- 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 151 (class 1259 OID 20059)
-- Dependencies: 142 5
-- 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 1879 (class 0 OID 0)
-- Dependencies: 151
-- Name: extracted_id_seq; Type: SEQUENCE OWNED BY; Schema: kc; Owner: postgres
--

ALTER SEQUENCE extracted_id_seq OWNED BY extracted.id;


--
-- TOC entry 143 (class 1259 OID 19950)
-- Dependencies: 1838 1839 5
-- 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 144 (class 1259 OID 19958)
-- Dependencies: 5
-- 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 145 (class 1259 OID 19961)
-- Dependencies: 5
-- 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 146 (class 1259 OID 19963)
-- Dependencies: 1840 5
-- Name: predicate; Type: TABLE; Schema: kc; Owner: postgres; Tablespace: 
--

CREATE TABLE predicate (
    id integer DEFAULT nextval('predicate_id_seq'::regclass) 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
);


ALTER TABLE kc.predicate OWNER TO postgres;

--
-- TOC entry 147 (class 1259 OID 19970)
-- Dependencies: 1841 5
-- 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 19977)
-- Dependencies: 5
-- 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 160 (class 1259 OID 20258)
-- Dependencies: 147 5
-- Name: term_eq_id_seq1; Type: SEQUENCE; Schema: kc; Owner: postgres
--

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


ALTER TABLE kc.term_eq_id_seq1 OWNER TO postgres;

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

ALTER SEQUENCE term_eq_id_seq1 OWNED BY term_eq.id;


--
-- TOC entry 149 (class 1259 OID 19979)
-- Dependencies: 1843 5
-- 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 19986)
-- Dependencies: 5
-- 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 161 (class 1259 OID 20658)
-- Dependencies: 149 5
-- Name: type_id_seq1; Type: SEQUENCE; Schema: kc; Owner: postgres
--

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


ALTER TABLE kc.type_id_seq1 OWNER TO postgres;

--
-- TOC entry 1881 (class 0 OID 0)
-- Dependencies: 161
-- Name: type_id_seq1; Type: SEQUENCE OWNED BY; Schema: kc; Owner: postgres
--

ALTER SEQUENCE type_id_seq1 OWNED BY type.id;


--
-- TOC entry 1837 (class 2604 OID 20061)
-- Dependencies: 151 142
-- Name: id; Type: DEFAULT; Schema: kc; Owner: postgres
--

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


--
-- TOC entry 1842 (class 2604 OID 20260)
-- Dependencies: 160 147
-- Name: id; Type: DEFAULT; Schema: kc; Owner: postgres
--

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


--
-- TOC entry 1844 (class 2604 OID 20660)
-- Dependencies: 161 149
-- Name: id; Type: DEFAULT; Schema: kc; Owner: postgres
--

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


--
-- TOC entry 1846 (class 2606 OID 19989)
-- 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 1848 (class 2606 OID 20171)
-- Dependencies: 142 142
-- Name: extracted_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

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


--
-- TOC entry 1850 (class 2606 OID 20169)
-- Dependencies: 142 142 142
-- 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 1852 (class 2606 OID 19993)
-- Dependencies: 143 143
-- Name: kc_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

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


--
-- TOC entry 1854 (class 2606 OID 19995)
-- Dependencies: 144 144 144
-- Name: maptable_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

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


--
-- TOC entry 1856 (class 2606 OID 19997)
-- Dependencies: 146 146
-- Name: predicate_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

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


--
-- TOC entry 1858 (class 2606 OID 20270)
-- Dependencies: 147 147
-- 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 1860 (class 2606 OID 20268)
-- Dependencies: 147 147 147
-- 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 1863 (class 2606 OID 20682)
-- Dependencies: 149 149 149
-- 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 1865 (class 2606 OID 20668)
-- Dependencies: 149 149
-- Name: type_pkey; Type: CONSTRAINT; Schema: kc; Owner: postgres; Tablespace: 
--

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


--
-- TOC entry 1861 (class 1259 OID 20701)
-- Dependencies: 149 149
-- Name: class_instance_index; Type: INDEX; Schema: kc; Owner: postgres; Tablespace: 
--

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


--
-- TOC entry 1866 (class 2606 OID 20002)
-- Dependencies: 1845 142 141
-- 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 1867 (class 2606 OID 20007)
-- Dependencies: 142 143 1851
-- 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 1868 (class 2606 OID 20012)
-- Dependencies: 144 146 1855
-- 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 1869 (class 2606 OID 20017)
-- Dependencies: 1855 144 146
-- 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 1870 (class 2606 OID 20022)
-- Dependencies: 143 1851 146
-- 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 1871 (class 2606 OID 20027)
-- Dependencies: 143 146 1851
-- 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 1872 (class 2606 OID 20032)
-- Dependencies: 1851 146 143
-- 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 1873 (class 2606 OID 20037)
-- Dependencies: 143 146 1851
-- 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 1874 (class 2606 OID 20042)
-- Dependencies: 147 143 1851
-- 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 1875 (class 2606 OID 20047)
-- Dependencies: 149 1851 143
-- 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 1876 (class 2606 OID 20052)
-- Dependencies: 143 149 1851
-- 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-06-07 19:58:29

--
--

