From: <cmu...@us...> - 2008-11-05 23:57:08
|
Revision: 2204 http://obo.svn.sourceforge.net/obo/?rev=2204&view=rev Author: cmungall Date: 2008-11-05 23:57:02 +0000 (Wed, 05 Nov 2008) Log Message: ----------- Modified Paths: -------------- OBDAPI/trunk/scripts/obd-reasoner.pl OBDAPI/trunk/sql/api/obd-mutable-api.plpgsql OBDAPI/trunk/sql/obd-birn-views.sql Added Paths: ----------- OBDAPI/trunk/conf/obd-birn/ OBDAPI/trunk/conf/obd-birn/Makefile Added: OBDAPI/trunk/conf/obd-birn/Makefile =================================================================== --- OBDAPI/trunk/conf/obd-birn/Makefile (rev 0) +++ OBDAPI/trunk/conf/obd-birn/Makefile 2008-11-05 23:57:02 UTC (rev 2204) @@ -0,0 +1,8 @@ +sao.obo: + cd /Users/cjm/cvs/obo/ontology/anatomy/anatomy_xp/ && make sao.obo + +remake-sao.obo: + cd /Users/cjm/cvs/obo/ontology/anatomy/anatomy_xp/ && rm sao.obo && make sao.obo + +all.obo: + blip -import_all -debug load -debug ontol io-convert -f owl -i http://ccdb.ucsd.edu/SAO/DPO/1.0/HumanDPO.owl -i http://ccdb.ucsd.edu/SAO/DPO/1.0/DPO.owl -i http://ccdb.ucsd.edu/SAO/DPO/1.0/ImagePhenotype.owl -i http://ccdb.ucsd.edu/SAO/PDSO/1.0/PDSO.owl -to obo -o $@ \ No newline at end of file Modified: OBDAPI/trunk/scripts/obd-reasoner.pl =================================================================== --- OBDAPI/trunk/scripts/obd-reasoner.pl 2008-11-05 00:08:09 UTC (rev 2203) +++ OBDAPI/trunk/scripts/obd-reasoner.pl 2008-11-05 23:57:02 UTC (rev 2204) @@ -20,6 +20,7 @@ my $verbose = 0; my %ruleconf = (); my $test_intersection; +my $infer_instance_of; while (@ARGV && $ARGV[0] =~ /^\-/) { my $opt = shift @ARGV; if ($opt eq '-d' || $opt eq '--database') { @@ -55,6 +56,9 @@ elsif ($opt eq '--rule') { $ruleconf{shift @ARGV}=1; } + elsif ($opt eq '--inst') { + $infer_instance_of = 1; + } else { die $opt; } @@ -91,6 +95,13 @@ } my $is_a = shift @is_a_nodes; +my @instance_of_nodes = + $dbh->selectrow_array("SELECT node_id FROM node WHERE uid='OBO_REL:instance_of'"); +if (@instance_of_nodes != 1) { + die "@instance_of_nodes"; +} +my $instance_of = shift @instance_of_nodes; + # TODO: use this below my @transitive_relation_node_ids = $dbh->selectrow_array("SELECT node_id FROM node WHERE is_transitive='t'"); @@ -246,8 +257,18 @@ #print STDERR "$sql\n"; # we do this at the start - unless new intersections can be added unshift(@views, - {id=>"intersection_for_$node_id", - sql=>$sql}); + {id=>"intersection_for_$node_id", + sql=>$sql}); + if ($infer_instance_of) { + my $sql = intersection_to_query($node_id,$intersection_h,1); + #print STDERR "$sql\n"; + # we do this at the start - unless new intersections can be added + unshift(@views, + {id=>"instance_intersection_for_$node_id", + sql=>$sql}); + } + + } my $done = 0; @@ -362,6 +383,7 @@ sub intersection_to_query { my $defined_node_id = shift; my $i_h = shift; + my $is_inst = shift; my @conds = @$i_h; my $linknum=0; my @links = (); @@ -374,17 +396,32 @@ $linknum++; my $link = "link_".$linknum; push(@links,"link AS $link"); + my $q; + my $pred_id = $_->{predicate_id}; + if ($is_inst) { + if ($pred_id == $is_a) { + $pred_id = $instance_of; + $q = "$link.node_id=subsumed_node.node_id AND $link.predicate_id = $instance_of AND $link.object_id = $_->{object_id} AND $link.combinator!='U'"; + } + else { + $q = "$link.node_id=subsumed_node.node_id AND $link.predicate_id = $pred_id AND $link.object_id IN (SELECT node_id FROM instantiation_link WHERE object_id= $_->{object_id}) AND $link.combinator!='U'"; + } + } + else { + $q = "$link.node_id=subsumed_node.node_id AND $link.predicate_id = $pred_id AND $link.object_id = $_->{object_id} AND $link.combinator!='U'"; + } # TODO: omit negation links - my $q = "$link.node_id=subsumed_node.node_id AND $link.predicate_id = $_->{predicate_id} AND $link.object_id = $_->{object_id} AND $link.combinator!='U'"; $q; } @conds); my $from = join(', ',@links); - + + my $inf_pred_id = $is_inst ? $instance_of : $is_a; + my $sql = qq[ SELECT DISTINCT subsumed_node.node_id AS node_id, - $is_a AS predicate_id, + $inf_pred_id AS predicate_id, $defined_node_id AS object_id FROM node AS subsumed_node, $from WHERE Modified: OBDAPI/trunk/sql/api/obd-mutable-api.plpgsql =================================================================== --- OBDAPI/trunk/sql/api/obd-mutable-api.plpgsql 2008-11-05 00:08:09 UTC (rev 2203) +++ OBDAPI/trunk/sql/api/obd-mutable-api.plpgsql 2008-11-05 23:57:02 UTC (rev 2204) @@ -1,6 +1,9 @@ -- CREATE SCHEMA obd_mutable_api; -- SET search_path TO obd_mutable_api,public; +TODO + + -- @@ store_node(UID,label,source,metatype) CREATE OR REPLACE FUNCTION store_node (VARCHAR,VARCHAR,VARCHAR,VARCHAR) RETURNS INT AS @@ -18,6 +21,26 @@ IF v_source IS NOT NULL THEN SELECT INTO v_source_id store_node(v_source); END IF; + RETURN SELECT store_node(v_uid,v_label,v_source_id,v_metatype); + END +$$ LANUAGE 'plpgsql'; + +CREATE OR REPLACE FUNCTION store_node (VARCHAR,VARCHAR,VARCHAR,VARCHAR) + RETURNS INT AS +$$ +DECLARE + v_uid ALIAS FOR $1; + v_label ALIAS FOR $2; + v_source ALIAS FOR $3; + v_metatype ALIAS FOR $4; + + v_node_id INTEGER; + v_source_id INTEGER; + BEGIN + + IF v_source IS NOT NULL THEN + SELECT INTO v_source_id store_node(v_source); + END IF; SELECT INTO v_node_id node_id FROM node WHERE uid=v_uid; @@ -600,12 +623,14 @@ UPDATE link SET reiflink_node_id=get_node_id($2) WHERE predicate_id=get_node_id($1) AND is_inferred='f'; $$ LANGUAGE 'sql'; -CREATE OR REPLACE FUNCTION store_genus_differentium(INT,INT,INT) RETURNS INT AS +-- store_genus_differentium(genus,predicate,filler,xp_source) RETURNS INT +CREATE OR REPLACE FUNCTION store_genus_differentium(INT,INT,INT,INT) RETURNS INT AS $$ DECLARE v_genus_id ALIAS FOR $1; v_relation_id ALIAS FOR $2; v_filler_id ALIAS FOR $3; + v_source_id ALIAS FOR $3; v_xp_uid VARCHAR; v_is_a_id INT; v_node_id INT; @@ -613,7 +638,7 @@ SELECT INTO v_xp_uid node_uid(v_genus_id) || '^' || node_uid(v_relation_id) || '(' || node_uid(v_filler_id) || ')'; SELECT INTO v_node_id node_id FROM node WHERE uid=v_xp_uid; IF NOT FOUND THEN - SELECT INTO v_node_id store_node(v_xp_uid); + SELECT INTO v_node_id store_node(v_xp_uid,CAST(null AS VARCHAR),'',CAST('C' AS VARCHAR)); SELECT INTO v_is_a_id node_id FROM is_a_relation; INSERT INTO link (node_id,predicate_id,object_id,combinator) VALUES (v_node_id,v_is_a_id,v_genus_id,'I'); INSERT INTO link (node_id,predicate_id,object_id,combinator) VALUES (v_node_id,v_relation_id,v_filler_id,'I'); Modified: OBDAPI/trunk/sql/obd-birn-views.sql =================================================================== --- OBDAPI/trunk/sql/obd-birn-views.sql 2008-11-05 00:08:09 UTC (rev 2203) +++ OBDAPI/trunk/sql/obd-birn-views.sql 2008-11-05 23:57:02 UTC (rev 2204) @@ -1,8 +1,8 @@ -- execute this AFTER data population -- SELECT realize_all_relations(); +SELECT realize_class('BIRN_PDPO.Phenotype'); - CREATE OR REPLACE VIEW phenotype_of AS SELECT ph.uid, @@ -48,6 +48,32 @@ ni.object_id, oi.object_id; +CREATE OR REPLACE VIEW inferred_inheres_in_with_types_c AS + SELECT + ni.object_id AS node_type_id, + oi.object_id AS object_type_id, + count(DISTINCT inh.node_id) AS num_instances + FROM + OBO_REL.inheres_in AS inh + INNER JOIN OBO_REL.instance_of AS ni ON (inh.node_id=ni.node_id) + INNER JOIN OBO_REL.instance_of AS oi ON (inh.object_id=oi.node_id) + GROUP BY + ni.object_id, + oi.object_id; + +CREATE OR REPLACE VIEW inferredR_inheres_in_with_types_c AS + SELECT + ni.object_id AS node_type_id, + oi.object_id AS object_type_id, + count(DISTINCT inh.node_id) AS num_instances + FROM + OBO_REL.inheres_in AS inh + INNER JOIN asserted_OBO_REL.instance_of AS ni ON (inh.node_id=ni.node_id) + INNER JOIN OBO_REL.instance_of AS oi ON (inh.object_id=oi.node_id) + GROUP BY + ni.object_id, + oi.object_id; + CREATE OR REPLACE VIEW has_part_with_types_c AS SELECT ni.object_id AS node_type_id, @@ -61,16 +87,45 @@ ni.object_id, oi.object_id; +CREATE OR REPLACE VIEW inferred_has_part_with_types_c AS + SELECT + ni.object_id AS node_type_id, + oi.object_id AS object_type_id, + count(DISTINCT inh.node_id) AS num_instances + FROM + OBO_REL.has_part AS inh + INNER JOIN OBO_REL.instance_of AS ni ON (inh.node_id=ni.node_id) + INNER JOIN OBO_REL.instance_of AS oi ON (inh.object_id=oi.node_id) + GROUP BY + ni.object_id, + oi.object_id; + +-- +CREATE OR REPLACE VIEW inferredR_has_part_with_types_c AS + SELECT + ni.object_id AS node_type_id, + oi.object_id AS object_type_id, + count(DISTINCT inh.node_id) AS num_instances + FROM + OBO_REL.has_part AS inh + INNER JOIN asserted_OBO_REL.instance_of AS ni ON (inh.node_id=ni.node_id) + INNER JOIN OBO_REL.instance_of AS oi ON (inh.object_id=oi.node_id) + GROUP BY + ni.object_id, + oi.object_id; + -- note that in the above asserted instance_of is used: for a wider variety -- consider inferred -CREATE OR REPLACE FUNCTION create_birn_xps() RETURNS SETOF RECORD AS +CREATE OR REPLACE FUNCTION create_birn_xps(INT) RETURNS SETOF RECORD AS $$ - SELECT store_genus_differentium(node_type_id,get_node_id('OBO_REL:inheres_in'),object_type_id) FROM inheres_in_with_types_c + SELECT store_genus_differentium(node_type_id,get_node_id('OBO_REL:inheres_in'),object_type_id,$1) FROM inferred_inheres_in_with_types_c WHERE node_type_id NOT IN (SELECT node_id FROM intersection_link) UNION - SELECT store_genus_differentium(node_type_id,get_node_id('OBO_REL:has_part'),object_type_id) FROM has_part_with_types_c + SELECT store_genus_differentium(node_type_id,get_node_id('OBO_REL:has_part'),object_type_id,$1) FROM inferred_has_part_with_types_c WHERE node_type_id NOT IN (SELECT node_id FROM intersection_link) $$ LANGUAGE 'sql'; --- select reify_links_by_predicate('BIRN_PDPO:bears','BIRN:generic_annotation'); +-- DO THIS ONCE: +-- load generic annotation first +-- SELECT reify_links_by_predicate('BIRN_PDPO:bears','BIRN:generic_annotation'); -- local closed-world axioms CREATE SCHEMA cwaxiom; @@ -102,3 +157,4 @@ FROM BIRN_PDPO.phenotype AS ph WHERE NOT EXISTS (SELECT * FROM BIRN_PDPO.is_born_by AS ibb WHERE ibb.node_id=ph.node_id AND birnlex_ubo.birnlex_2(ibb.object_id)); + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |