Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add forward chaining inference

  • Loading branch information...
commit 212cf5a3de4200c1466ba9909d8868f258eeba18 1 parent 66973e9
Li Ding authored May 24, 2011
39  src-xqy/hs-ld.20110418/owl-inference.xqy
... ...
@@ -0,0 +1,39 @@
  1
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  2
+sem:inf-owl2rl-eq-sym();
  3
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  4
+sem:inf-owl2rl-eq-trans();
  5
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  6
+sem:inf-owl2rl-eq-rep-s();
  7
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  8
+sem:inf-owl2rl-eq-rep-p();
  9
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  10
+sem:inf-owl2rl-eq-rep-o();
  11
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  12
+sem:inf-owl2rl-prp-symp();
  13
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  14
+sem:inf-owl2rl-prp-trp();
  15
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  16
+sem:inf-owl2rl-prp-inv1();
  17
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  18
+sem:inf-owl2rl-prp-inv2();
  19
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  20
+sem:inf-owl2rl-scm-sco();
  21
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  22
+sem:inf-owl2rl-scm-spo();
  23
+
  24
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  25
+sem:inf-owl2rl-prp-spo1();
  26
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  27
+sem:inf-owl2rl-cls-hv1();
  28
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  29
+sem:inf-owl2rl-cls-hv2();
  30
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  31
+sem:inf-owl2rl-cax-sco();
  32
+
  33
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  34
+sem:inf-owl2rl-scm-cls();
  35
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  36
+sem:inf-owl2rl-scm-op();
  37
+import module namespace sem="http://marklogic.com/semantic" at "semantic.xqy";
  38
+sem:inf-owl2rl-scm-dp();
  39
+()
848  src-xqy/hs-ld.20110418/semantic.xqy
@@ -875,46 +875,84 @@ declare function sem:select(
875 875
 
876 876
 (: source https://github.com/marklogic/semantic/raw/master/src/xquery/semantic.xqy :)
877 877
 
878  
-(: --- enhancement ---  :)
879 878
 
880  
-(: shortcut for sem:rq :)
  879
+
  880
+
  881
+(: 
  882
+ : -------------------------------------
  883
+ : PART 2 enhancement
  884
+ : -------------------------------------
  885
+ :)
  886
+ 
  887
+declare variable $sem:P-OWL-INVERSE :=
  888
+'http://www.w3.org/2002/07/owl#inverseOf'
  889
+;
  890
+
  891
+declare variable $sem:C-OWL-TRANSITIVE-PROPERTY :=
  892
+'http://www.w3.org/2002/07/owl#TransitiveProperty'
  893
+;
  894
+ 
  895
+declare variable $sem:C-OWL-SYMMETRIC-PROPERTY :=
  896
+'http://www.w3.org/2002/07/owl#SymmetricProperty'
  897
+;
  898
+
  899
+declare variable $sem:P-OWL-SAMEAS :=
  900
+'http://www.w3.org/2002/07/owl#sameAs'
  901
+;
  902
+
  903
+
  904
+declare variable $sem:P-OWL-HAS-VALUE :=
  905
+'http://www.w3.org/2002/07/owl#hasValue'
  906
+;
  907
+
  908
+
  909
+declare variable $sem:O-OWL-DATATYPE-PROPERTY :=
  910
+'http://www.w3.org/2002/07/owl#DatatypeProperty'
  911
+;
  912
+ 
  913
+
  914
+(: 
  915
+ : -------------------------------------
  916
+ : PART 2.1 wrappers
  917
+ :	- query constructor
  918
+ :	- query evaluation
  919
+ : -------------------------------------
  920
+ :)
  921
+
  922
+(: shortcut for sem:rq, create a query pattern on subject :)
881 923
 declare  function sem:query-s(
882 924
   $s as xs:string*)
883  
- as cts:query?
  925
+ as cts:query
884 926
 {
885 927
   if (empty($s)) 
886 928
   then sem:rq($sem:QN-S, '')
887 929
   else sem:rq($sem:QN-S, $s)
888 930
 };
889 931
 
890  
-(: shortcut for sem:rq :)
  932
+(: shortcut for sem:rq, create a query pattern on object :)
891 933
 declare  function sem:query-o(
892 934
   $o as xs:string*)
893  
- as cts:query?
  935
+ as cts:query
894 936
 {
895 937
   if (empty($o)) 
896 938
   then sem:rq($sem:QN-O, '')
897 939
   else sem:rq($sem:QN-O, $o)
898 940
 };
899  
-(: with sub-property inference :)
900  
-(:  sem:rq($sem:QN-O, sem:rdf-subclasses($o) ) :)
901  
-(:  sem:rq($sem:QN-O, sem:owl-subclasses($o))  :)
902  
-
903 941
 
904  
-(: shortcut for sem:pq :)
  942
+(: shortcut for sem:rq, create a query pattern on predicate :)
905 943
 declare function sem:query-p(
906 944
   $p as xs:string*)
907  
- as cts:query?
  945
+ as cts:query
908 946
 {
909 947
   if (empty($p)) 
910  
-  then sem:pq('')
911  
-  else sem:pq($p)
  948
+  then sem:rq($sem:QN-P, '')
  949
+  else sem:rq($sem:QN-P, $p)
912 950
 };
913 951
 
914  
-(: query c :)
  952
+(: shortcut for sem:rq, create a query pattern on context (named graph) :)
915 953
 declare function sem:query-c(
916 954
   $c as xs:string*)
917  
- as cts:query?
  955
+ as cts:query
918 956
 {
919 957
   if (empty($c)) 
920 958
   then sem:rq($sem:QN-C, '') 
@@ -922,46 +960,7 @@ declare function sem:query-c(
922 960
 };
923 961
 
924 962
 
925  
-
926  
-(: with sub-property inference :)
927  
-(:  sem:pq(sem:list-direct-subproperties($p))  :)
928  
-
929  
-(: compute inverse :)
930  
-declare variable $sem:P-OWL-INVERSE :=
931  
-'http://www.w3.org/2002/07/owl#inverseOf'
932  
-;
933  
-
934  
-declare function sem:owl-inverse(
935  
-  $p as xs:string*)
936  
-as xs:string*
937  
-{
938  
-  if (empty($p)) then () else
939  
-  sem:merge-sequence(
940  
-	sem:subject-for-object-predicate($p, $sem:P-OWL-INVERSE),
941  
-    sem:object-for-subject-predicate($p, $sem:P-OWL-INVERSE)
942  
-  )
943  
-};
944  
-
945  
-(: compute transitive closure :)
946  
-declare function sem:tc-s($seeds as xs:string* , $p as xs:string*)
947  
-   as xs:string* {
948  
-      let $next := sem:object-for-subject-predicate($seeds, $p)
949  
-	  return
950  
-	  if ( $next ) then ($seeds , sem:tc-s($next, $p) )
951  
-	  else ($seeds)
952  
-}; 
953  
-
954  
-(: compute transitive closure :)
955  
-declare function sem:tc-o($seeds as xs:string* , $p as xs:string*)
956  
-   as xs:string* {
957  
-      let $next := sem:subject-for-object-predicate($seeds, $p)
958  
-      return 
959  
-	    if ( $next ) then ($seeds , sem:tc-o($next, $p))
960  
-	    else ($seeds)
961  
-}; 
962  
-
963  
-
964  
-(: evaluate a list of queries :)
  963
+(: evaluate a list of queries, return a list of strings :)
965 964
 declare function sem:ev1(
966 965
   $qn as xs:QName, 
967 966
   $query as cts:query*)
@@ -972,7 +971,7 @@ as xs:string*
972 971
 	else sem:ev($qn, cts:and-query( $query) )
973 972
 };
974 973
 
975  
-(: evaluate a list of queries :)
  974
+(: evaluate a list of queries, return a list of triples :)
976 975
 declare function sem:evT(
977 976
   $query as cts:query*)
978 977
 as element(t)*
@@ -982,7 +981,16 @@ as element(t)*
982 981
 	else sem:tuples-for-query(cts:and-query( $query) )
983 982
 };
984 983
 
985  
-declare function sem:merge-sequence(
  984
+
  985
+
  986
+
  987
+(: 
  988
+ : -------------------------------------
  989
+ : PART 2.2 Set Operations
  990
+ : -------------------------------------
  991
+ :)
  992
+ 
  993
+declare function sem:setop-union(
986 994
   $seq1 as item()*,
987 995
   $seq2 as item()*)
988 996
 as item()*
@@ -994,133 +1002,48 @@ as item()*
994 1002
   for $y in $seq2
995 1003
   return ($x, $y)
996 1004
 };
997  
-
998  
-(: shortcut for sem:relate-join :)
999  
-declare function sem:ev2(
1000  
-  $a as xs:QName, 
1001  
-  $b as xs:QName,
1002  
-  $query as cts:query )
1003  
-as element(cts:co-occurrence)*
1004  
-{
1005  
-  sem:relate-join ( $a, $b, $query)
  1005
+ 
  1006
+declare function sem:setop-distinct-element($seq as element()*, $m as map:map) {
  1007
+    for $e in $seq
  1008
+    return map:put($m, $e,$e)  
1006 1009
 };
1007 1010
 
1008  
-(: merge bindings with one variable result, zero pre-existing variable :)
1009  
-declare function sem:merge_1_0(
1010  
-  $bindings as element(binding)*,
1011  
-  $data as xs:string*,
1012  
-  $co_field1_name as xs:string
1013  
- )
1014  
-as element(binding)*
1015  
- {
1016  
-  if (empty($data)) then error((),'empty results')
1017  
-  else 
1018  
-  if (empty($bindings)) then (
1019  
-    for $d in $data
1020  
-    return ( element binding 
1021  
-      {element {$co_field1_name} {$d} }
1022  
-    )
1023  
-  )
1024  
-  else
1025  
-    for $d in $data
1026  
-    for $t in $bindings
1027  
-    return ( element binding 
1028  
-      {$t/*, element {$co_field1_name} {$d} }
1029  
-    )
1030  
-   
1031  
- };
1032  
-
1033  
-(: merge bindings with one variable result, one pre-existing variable :)
1034  
-declare function sem:merge_1_1(
1035  
-  $bindings as element(binding)+,
1036  
-  $data as xs:string*,
1037  
-  $co_field1_name as xs:string
1038  
- )
1039  
-as element(binding)*
1040  
- {
1041  
-  if (empty($data)) then error((),'empty results')
1042  
-  else 
1043  
-  if (empty($bindings)) then  error((),'empty results')
1044  
-  else
1045  
-    for $d in $data
1046  
-    for $t in $bindings
1047  
-    where ($t/node()[name()=$co_field1_name]/string() = $d)
1048  
-     return ( element binding 
1049  
-      {$t/*}
1050  
-    )
1051  
- };
  1011
+declare function sem:setop-distinct-element($seq as element()*) {
  1012
+  let $m := map:map()
  1013
+  let $x := sem:setop-distinct-element($seq, $m)
  1014
+  for $y in map:keys($m)
  1015
+  return map:get($m,$y)
  1016
+};
1052 1017
 
  1018
+declare function sem:setop-intersect($m as map:map, $seq1 as element()*, $seq2 as element()*) {
  1019
+    for $e1 in $seq1
  1020
+    for $e2 in $seq2
  1021
+    where deep-equal($e1,$e2)
  1022
+    return map:put($m, $e1,$e1) 
  1023
+};
1053 1024
  
1054  
-(: merge bindings with two variable co-existing result, no pre-existing variable :)
1055  
-declare function sem:merge_2_0(
1056  
-  $bindings as element(binding)*,
1057  
-  $co as element(cts:co-occurrence)*,
1058  
-  $co_field1_name as xs:string,
1059  
-  $co_field2_name as xs:string
1060  
- )
1061  
-as element(binding)*
1062  
- {
1063  
-  if (empty($co)) then  error((),'empty results')
1064  
-  else 
1065  
-  if (empty($bindings)) then (
1066  
-  for $c in $co
1067  
-  return ( element binding 
1068  
-    {element {$co_field1_name} {$c/cts:value[1]/string()} ,
1069  
-    element {$co_field2_name} {$c/cts:value[2]/string()} }
1070  
-   )
1071  
-  )
1072  
-  else
1073  
-  for $c in $co
1074  
-  for $t in $bindings
1075  
-  return ( element binding 
1076  
-    {$t/*, element {$co_field1_name} {$c/cts:value[1]/string()} ,
1077  
-    element {$co_field2_name} {$c/cts:value[2]/string()} }
1078  
-   )
1079  
- };
1080  
- 
1081  
- 
1082  
-(: merge bindings with two variable co-existing result, one pre-existing variable :)
1083  
- declare function sem:merge_2_1(
1084  
-  $bindings as element(binding)*,
1085  
-  $co as element(cts:co-occurrence)*,
1086  
-  $binding_field_join_name as xs:string,
1087  
-  $co_field_join_pos as xs:int,
1088  
-  $co_field_value_name as xs:string,
1089  
-  $co_field_value_pos as xs:int
1090  
-  )
1091  
-  as element(binding)*
1092  
- {
1093  
-  if (empty($co)) then  error((),'empty results')
1094  
-  else 
1095  
-  for $t in $bindings
1096  
-  for $c in $co 
1097  
-  where ($t/node()[name()=$binding_field_join_name]/string() = $c/cts:value[$co_field_join_pos]/string())
1098  
-  return ( element binding 
1099  
-	{$t/*,
1100  
-    element {$co_field_value_name} {$c/cts:value[$co_field_value_pos]/string()} }
1101  
-   )
1102  
- };
1103  
- 
1104  
-(: merge bindings with two variable co-existing result, two pre-existing variable :)
1105  
- declare function sem:merge_2_2(
1106  
-  $bindings as element(binding)*,
1107  
-  $co as element(cts:co-occurrence)*,
1108  
-  $co_field1_name as xs:string,
1109  
-  $co_field2_name as xs:string
  1025
+
  1026
+
  1027
+(: 
  1028
+ : -------------------------------------
  1029
+ : PART 2.3 dynamic inference
  1030
+ : -------------------------------------
  1031
+ :)
  1032
+
  1033
+
  1034
+(: list properties which are direct inverse of the input properties :)
  1035
+declare function sem:list-direct-owl-inverse(
  1036
+  $p as xs:string*)
  1037
+as xs:string*
  1038
+{
  1039
+  if (empty($p)) then () else
  1040
+  sem:setop-union(
  1041
+	sem:subject-for-object-predicate($p, $sem:P-OWL-INVERSE),
  1042
+    sem:object-for-subject-predicate($p, $sem:P-OWL-INVERSE)
1110 1043
   )
1111  
-  as element(binding)*
1112  
- {
1113  
-  if (empty($co)) then  error((),'empty results')
1114  
-  else 
1115  
-  for $t in $bindings
1116  
-  for $c in $co 
1117  
-  where (($t/node()[name()=$co_field1_name]/string() = $c/cts:value[1]/string()) and ($t/node()[name()=$co_field2_name]/string() = $c/cts:value[2]/string()))
1118  
-  return ( element binding 
1119  
-	{$t/*}
1120  
-   )
1121  
- };
1122  
- 
1123  
-(: list direct sub-classes :) 
  1044
+};
  1045
+
  1046
+(: list classes which are direct sub-classes of the input classes. Results include the input :) 
1124 1047
  declare function sem:list-direct-subclasses(
1125 1048
   $class as xs:string*)
1126 1049
 as xs:string*
@@ -1136,7 +1059,7 @@ as xs:string*
1136 1059
   )
1137 1060
 };
1138 1061
 
1139  
-(: list direct sub-property:) 
  1062
+(: list properties which are direct sub-properties of the input properties. Results include the input :) 
1140 1063
 declare function sem:list-direct-subproperties(
1141 1064
   $prop as xs:string*)
1142 1065
 as xs:string*
@@ -1153,63 +1076,526 @@ as xs:string*
1153 1076
 };
1154 1077
 
1155 1078
 
1156  
-(: create a quad :) 
1157  
-declare function sem:quad(
1158  
-  $s as xs:string,
1159  
-  $s_type as xs:string,
1160  
-  $p as xs:string,
1161  
-  $p_type as xs:string,
1162  
-  $o as xs:string,
1163  
-  $o_type as xs:string,
1164  
-  $c as xs:string?)
1165  
-as element(t)
  1079
+
  1080
+
  1081
+(: 
  1082
+ : -------------------------------------
  1083
+ : PART 2.4 forward chaining materialization inference
  1084
+ : -------------------------------------
  1085
+ :)
  1086
+
  1087
+ 
  1088
+(:  Forward-Chaining Inference -- general :)
  1089
+
  1090
+(:  insert a couple of documents encoded in map in form of  "document key" => "document content" :)
  1091
+declare function sem:inf-tuple-insert($m as map:map)
  1092
+as  empty-sequence()
1166 1093
 {
1167  
-  element t {
1168  
-    element s {
1169  
-      attribute h { xdmp:hash64($s) },
1170  
-      attribute type { $s_type },
1171  
-      $s },
1172  
-    element p {
1173  
-      attribute h { xdmp:hash64($p) },
1174  
-      attribute type { $p_type },
1175  
-      $p },
1176  
-    element o {
1177  
-      attribute h { xdmp:hash64($o) },
1178  
-      attribute type { $o_type },
1179  
-      $o },
1180  
-    if (empty($c)) 
1181  
-	then ()
1182  
-    else element c {
1183  
-      attribute h { xdmp:hash64($c) },
1184  
-      attribute type { 'uri' },
1185  
-      $c }
1186  
-  }
  1094
+  for $key in map:keys($m)
  1095
+  return  xdmp:document-insert($key, map:get($m, $key))
1187 1096
 };
1188 1097
 
1189  
-declare function sem:quad-insert(
1190  
-  $s as xs:string,
1191  
-  $s_type as xs:string,
1192  
-  $p as xs:string,
1193  
-  $p_type as xs:string,
1194  
-  $o as xs:string,
1195  
-  $o_type as xs:string,
1196  
-  $c as xs:string?)
  1098
+
  1099
+(:  Forward-Chaining Inference -- add owl2 ontology :)
  1100
+
  1101
+declare function sem:inf-owl2-ontology()
  1102
+as xs:integer*{
  1103
+ (	
  1104
+   sem:tuple-insert( 'http://www.w3.org/2002/07/owl#SymmetricProperty' , 'http://www.w3.org/2000/01/rdf-schema#subClassOf' ,  'http://www.w3.org/2002/07/owl#ObjectProperty', 'http://www.w3.org/2002/07/owl' ),
  1105
+   sem:tuple-insert( 'http://www.w3.org/2002/07/owl#TransitiveProperty' , 'http://www.w3.org/2000/01/rdf-schema#subClassOf' ,  'http://www.w3.org/2002/07/owl#ObjectProperty', 'http://www.w3.org/2002/07/owl' ),
  1106
+   ()
  1107
+ )
  1108
+};
  1109
+
  1110
+
  1111
+
  1112
+(:  Forward-Chaining Inference -- OWL2RL rules http://www.w3.org/TR/owl2-profiles/#OWL_2_RL :)
  1113
+
  1114
+
  1115
+(: owl2rl | eq-sym | sameAs :)
  1116
+declare function sem:inf-owl2rl-eq-sym()
  1117
+as xs:integer
  1118
+{
  1119
+  let $m := map:map()
  1120
+  let $query := sem:inf-owl2rl-eq-sym($m)
  1121
+  let $exec := sem:inf-tuple-insert($m)
  1122
+  return map:count($m)
  1123
+};
  1124
+
  1125
+declare private function sem:inf-owl2rl-eq-sym($m as map:map)
  1126
+as  empty-sequence()
  1127
+{
  1128
+  for  $t_x_y in sem:evT( sem:query-p( $sem:P-OWL-SAMEAS ) ) 
  1129
+      , $x in $t_x_y/s/text()
  1130
+      , $y in $t_x_y/o/text()
  1131
+  let $key := sem:uri-for-tuple($y, $sem:P-OWL-SAMEAS, $x, '')
  1132
+  where (($x != $y) and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1133
+  return map:put(
  1134
+      $m, 
  1135
+      $key,   
  1136
+      sem:tuple($y, $sem:P-OWL-SAMEAS, $x, '')) 
  1137
+};
  1138
+ 
  1139
+
  1140
+
  1141
+(: owl2rl | eq-trans | sameAs :)
  1142
+declare function sem:inf-owl2rl-eq-trans()
  1143
+as xs:integer
  1144
+{
  1145
+  let $m := map:map()
  1146
+  let $query := sem:inf-owl2rl-eq-trans($m)
  1147
+  let $exec := sem:inf-tuple-insert($m)
  1148
+  return map:count($m)
  1149
+};
  1150
+
  1151
+declare private function sem:inf-owl2rl-eq-trans($m as map:map)
1197 1152
 as empty-sequence()
1198 1153
 {
1199  
-  xdmp:document-insert(
1200  
-    sem:uri-for-tuple($s, $p, $o, $c),
1201  
-    sem:quad($s, $s_type, $p, $p_type, $o, $o_type, $c) )
  1154
+  for  $t_x_y in sem:evT( sem:query-p( $sem:P-OWL-SAMEAS ) ) 
  1155
+      , $x in $t_x_y/s/text()
  1156
+      , $y in $t_x_y/o/text()
  1157
+  for  $z in sem:ev1( $sem:QN-O, (sem:query-s( $y ), sem:query-p( $sem:P-OWL-SAMEAS ) )) 
  1158
+  let $key := sem:uri-for-tuple($x, $sem:P-OWL-SAMEAS, $z, '')
  1159
+  where (($x != $y) and ($y != $z) and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) ) 
  1160
+  return map:put(
  1161
+      $m, 
  1162
+      $key,   
  1163
+      sem:tuple($x, $sem:P-OWL-SAMEAS, $z, '')) 
1202 1164
 };
  1165
+ 
1203 1166
 
1204  
-(: sameAs support  :)
1205  
-declare function sem:list-sameas(
1206  
-  $list as xs:string*)
1207  
-as xs:string*
  1167
+
  1168
+(: owl2rl | eq-rep-s | sameAs :)
  1169
+declare function sem:inf-owl2rl-eq-rep-s()
  1170
+as xs:integer
  1171
+{
  1172
+  let $m := map:map()
  1173
+  let $query := sem:inf-owl2rl-eq-rep-s($m)
  1174
+  let $exec := sem:inf-tuple-insert($m)
  1175
+  return map:count($m)
  1176
+};
  1177
+
  1178
+declare private function sem:inf-owl2rl-eq-rep-s($m as map:map)
  1179
+as  empty-sequence()
  1180
+{
  1181
+  for  $t_x_y in sem:evT( sem:query-p( $sem:P-OWL-SAMEAS ) ) 
  1182
+      , $x in $t_x_y/s/text()
  1183
+      , $y in $t_x_y/o/text()
  1184
+  for  $t_p_o in sem:evT( sem:query-s( $x ) ) 
  1185
+      , $p in $t_p_o/p/text()
  1186
+      , $o in $t_p_o/o/text()
  1187
+  let $key := sem:uri-for-tuple($y, $p, $o, '')
  1188
+  where (($x != $y) and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) ) 
  1189
+  return map:put(
  1190
+      $m, 
  1191
+      $key,   
  1192
+      sem:tuple($y, $p, $o, '')) 
  1193
+};
  1194
+ 
  1195
+ 
  1196
+ 
  1197
+(: owl2rl | eq-rep-p | sameAs :)
  1198
+declare function sem:inf-owl2rl-eq-rep-p()
  1199
+as xs:integer
  1200
+{
  1201
+  let $m := map:map()
  1202
+  let $query := sem:inf-owl2rl-eq-rep-p($m)
  1203
+  let $exec := sem:inf-tuple-insert($m)
  1204
+  return map:count($m)
  1205
+};
  1206
+
  1207
+declare private function sem:inf-owl2rl-eq-rep-p($m as map:map)
  1208
+as  empty-sequence()
  1209
+{
  1210
+  for  $t_x_y in sem:evT( sem:query-p( $sem:P-OWL-SAMEAS ) ) 
  1211
+      , $x in $t_x_y/s/text()
  1212
+      , $y in $t_x_y/o/text()
  1213
+  for  $t_s_o in sem:evT( sem:query-p( $x ) ) 
  1214
+      , $s in $t_s_o/s/text()
  1215
+      , $o in $t_s_o/o/text()
  1216
+  let $key := sem:uri-for-tuple($s, $y, $o, '')
  1217
+  where (($x != $y) and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) ) 
  1218
+  return map:put(
  1219
+      $m, 
  1220
+      $key,   
  1221
+      sem:tuple($s, $y, $o, '')) 
  1222
+};
  1223
+
  1224
+
  1225
+
  1226
+(: owl2rl | eq-rep-o | sameAs :)
  1227
+declare function sem:inf-owl2rl-eq-rep-o()
  1228
+as xs:integer
  1229
+{
  1230
+  let $m := map:map()
  1231
+  let $query := sem:inf-owl2rl-eq-rep-o($m)
  1232
+  let $exec := sem:inf-tuple-insert($m)
  1233
+  return map:count($m)
  1234
+};
  1235
+
  1236
+declare private function sem:inf-owl2rl-eq-rep-o($m as map:map)
  1237
+as  empty-sequence()
  1238
+{
  1239
+  for  $t_x_y in sem:evT( sem:query-p( $sem:P-OWL-SAMEAS ) ) 
  1240
+      , $x in $t_x_y/s/text()
  1241
+      , $y in $t_x_y/o/text()
  1242
+  for  $t_s_p in sem:evT( sem:query-o( $x ) ) 
  1243
+      , $s in $t_s_p/s/text()
  1244
+      , $p in $t_s_p/p/text()
  1245
+  let $key := sem:uri-for-tuple($s, $p, $y, '')
  1246
+  where (($x != $y) and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) ) 
  1247
+  return map:put(
  1248
+      $m, 
  1249
+      $key,   
  1250
+      sem:tuple($s, $p, $y, '')) 
  1251
+};
  1252
+
  1253
+
  1254
+
  1255
+
  1256
+(: owl2rl | prp-symp | SymmetricProperty :)
  1257
+declare function sem:inf-owl2rl-prp-symp()
  1258
+as xs:integer
  1259
+{
  1260
+  let $m := map:map()
  1261
+  let $query := sem:inf-owl2rl-prp-symp($m)
  1262
+  let $exec := sem:inf-tuple-insert($m)
  1263
+  return map:count($m)
  1264
+};
  1265
+
  1266
+declare private function sem:inf-owl2rl-prp-symp($m as map:map)
  1267
+as  empty-sequence()
  1268
+{
  1269
+  for  $p in sem:ev1(  $sem:QN-S, (sem:query-p( $sem:P-RDF-TYPE ), sem:query-o( $sem:C-OWL-SYMMETRIC-PROPERTY)) ) 
  1270
+  for  $t_x_y in sem:evT( sem:query-p( $p ) ) 
  1271
+      , $x in $t_x_y/s/text()
  1272
+      , $y in $t_x_y/o/text()
  1273
+  let $key := sem:uri-for-tuple($y, $p, $x, '')
  1274
+  where ( ($x != $y)  and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1275
+  return map:put(
  1276
+      $m, 
  1277
+      $key,   
  1278
+      sem:tuple($y, $p, $x, '')) 
  1279
+};
  1280
+
  1281
+
  1282
+
  1283
+
  1284
+(: owl2rl | prp-trp  | TransitiveProperty :)
  1285
+declare function sem:inf-owl2rl-prp-trp()
  1286
+as xs:integer
  1287
+{
  1288
+  let $m := map:map()
  1289
+  let $query := sem:inf-owl2rl-prp-trp($m)
  1290
+  let $exec := sem:inf-tuple-insert($m)
  1291
+  return map:count($m)
  1292
+};
  1293
+
  1294
+declare private function sem:inf-owl2rl-prp-trp($m as map:map)
  1295
+as empty-sequence()
  1296
+{
  1297
+  for  $p in sem:ev1(  $sem:QN-S, (sem:query-p( $sem:P-RDF-TYPE ), sem:query-o( $sem:C-OWL-TRANSITIVE-PROPERTY )) ) 
  1298
+  for  $t_x_y in sem:evT( sem:query-p( $p ) ) 
  1299
+      , $x in $t_x_y/s/text()
  1300
+      , $y in $t_x_y/o/text()
  1301
+  for  $z in sem:ev1( $sem:QN-O, (sem:query-s( $y ), sem:query-p( $p ) )) 
  1302
+  let $key := sem:uri-for-tuple($x, $p, $z, '')
  1303
+  where (($x != $y) and ($y != $z) and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) ) 
  1304
+  return map:put(
  1305
+      $m, 
  1306
+      $key,   
  1307
+      sem:tuple($x, $p, $z, '')) 
  1308
+};
  1309
+
  1310
+
  1311
+(: owl2rl | prp-spo1  | subPropertyOf inference :)
  1312
+declare function sem:inf-owl2rl-prp-spo1()
  1313
+as xs:integer
  1314
+{
  1315
+  let $m := map:map()
  1316
+  let $query := sem:inf-owl2rl-prp-spo1($m)
  1317
+  let $exec := sem:inf-tuple-insert($m)
  1318
+  return map:count($m)
  1319
+};
  1320
+
  1321
+declare private function sem:inf-owl2rl-prp-spo1($m as map:map)
  1322
+as empty-sequence()
  1323
+{
  1324
+  for  $t_p1_p2 in sem:evT( sem:query-p( $sem:P-RDF-SUBPROPERTY ) ) 
  1325
+      , $p1 in $t_p1_p2/s/text()
  1326
+      , $p2 in $t_p1_p2/o/text()
  1327
+  for  $t_x_y in sem:evT( sem:query-p( $p1 ) ) 
  1328
+      , $x in $t_x_y/s/text()
  1329
+      , $y in $t_x_y/o/text()
  1330
+  let $key := sem:uri-for-tuple($x, $p2, $y, '')
  1331
+  where ( ($p1 != $p2 ) and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) ) 
  1332
+  return map:put(
  1333
+      $m, 
  1334
+      $key,   
  1335
+      sem:tuple($x, $p2, $y, '')) 
  1336
+};
  1337
+
  1338
+
  1339
+ 
  1340
+(: owl2rl | prp-inv1  | inverseOf:)
  1341
+declare function sem:inf-owl2rl-prp-inv1()
  1342
+as xs:integer
  1343
+{
  1344
+  let $m := map:map()
  1345
+  let $query := sem:inf-owl2rl-prp-inv1($m)
  1346
+  let $exec := sem:inf-tuple-insert($m)
  1347
+  return map:count($m)
  1348
+};
  1349
+
  1350
+declare private function sem:inf-owl2rl-prp-inv1($m as map:map)
  1351
+as  empty-sequence()
  1352
+{
  1353
+  for  $t_x_y in sem:evT( sem:query-p( $sem:P-OWL-INVERSE ) ) 
  1354
+      , $x in $t_x_y/s/text()
  1355
+      , $y in $t_x_y/o/text()
  1356
+  for  $t_s_o in sem:evT( sem:query-p( $x ) ) 
  1357
+      , $s in $t_s_o/s/text()
  1358
+      , $o in $t_s_o/o/text()
  1359
+  let $key := sem:uri-for-tuple($o, $y, $s, '')
  1360
+  where ( ($x != $y)  and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1361
+  return map:put(
  1362
+      $m, 
  1363
+      $key,   
  1364
+      sem:tuple($o, $y, $s, '')) 
  1365
+};
  1366
+
  1367
+
  1368
+
  1369
+
  1370
+(: owl2rl | prp-inv2  | inverseOf:)
  1371
+declare function sem:inf-owl2rl-prp-inv2()
  1372
+as xs:integer
  1373
+{
  1374
+  let $m := map:map()
  1375
+  let $query := sem:inf-owl2rl-prp-inv2($m)
  1376
+  let $exec := sem:inf-tuple-insert($m)
  1377
+  return map:count($m)
  1378
+};
  1379
+
  1380
+declare private function sem:inf-owl2rl-prp-inv2($m as map:map)
  1381
+as  empty-sequence()
  1382
+{
  1383
+  for  $t_x_y in sem:evT( sem:query-p( $sem:P-OWL-INVERSE ) ) 
  1384
+      , $x in $t_x_y/s/text()
  1385
+      , $y in $t_x_y/o/text()
  1386
+  for  $t_s_o in sem:evT( sem:query-p( $y ) ) 
  1387
+      , $s in $t_s_o/s/text()
  1388
+      , $o in $t_s_o/o/text()
  1389
+  let $key := sem:uri-for-tuple($o, $x, $s, '')
  1390
+  where ( ($x != $y)  and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1391
+  return map:put(
  1392
+      $m, 
  1393
+      $key,   
  1394
+      sem:tuple($o, $x, $s, '')) 
  1395
+};
  1396
+
  1397
+
  1398
+(: owl2rl | cls-hv1  | owl:hasValue  :)
  1399
+declare function sem:inf-owl2rl-cls-hv1()
  1400
+as xs:integer
  1401
+{
  1402
+  let $m := map:map()
  1403
+  let $query := sem:inf-owl2rl-cls-hv1($m)
  1404
+  let $exec := sem:inf-tuple-insert($m)
  1405
+  return map:count($m)
  1406
+};
  1407
+
  1408
+declare private function sem:inf-owl2rl-cls-hv1($m as map:map)
  1409
+as  empty-sequence()
  1410
+{
  1411
+  for  $t_x_y in sem:evT( sem:query-p( $sem:P-OWL-HAS-VALUE ) ) 
  1412
+      , $x in $t_x_y/s/text()
  1413
+      , $y in $t_x_y/o/text()
  1414
+  for  $p in sem:ev1(  $sem:QN-O, (sem:query-p( $sem:P-OWL-ON-PROPERTY ), sem:query-s( $x )) ) 
  1415
+  for  $u in sem:ev1(  $sem:QN-S, (sem:query-p( $sem:P-RDF-TYPE ), sem:query-o( $x )) ) 
  1416
+  let $key := sem:uri-for-tuple($u, $p, $y, '')
  1417
+  where ( (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1418
+  return map:put(
  1419
+      $m, 
  1420
+      $key,   
  1421
+      sem:tuple($u, $p, $y, '')) 
  1422
+};
  1423
+
  1424
+
  1425
+(: owl2rl | cls-hv2  | owl:hasValue  :)
  1426
+declare function sem:inf-owl2rl-cls-hv2()
  1427
+as xs:integer
1208 1428
 {
1209  
-  if (empty($list) ) then () else
1210  
-      (
1211  
-		sem:subject-for-object-predicate( $list, 'http://www.w3.org/2002/07/owl#sameAs'),
1212  
-		sem:object-for-subject-predicate( $list, 'http://www.w3.org/2002/07/owl#sameAs')
1213  
-	  )
1214  
-  
  1429
+  let $m := map:map()
  1430
+  let $query := sem:inf-owl2rl-cls-hv2($m)
  1431
+  let $exec := sem:inf-tuple-insert($m)
  1432
+  return map:count($m)
1215 1433
 };
  1434
+
  1435
+declare private function sem:inf-owl2rl-cls-hv2($m as map:map)
  1436
+as  empty-sequence()
  1437
+{
  1438
+  for  $t_x_y in sem:evT( sem:query-p( $sem:P-OWL-HAS-VALUE ) ) 
  1439
+      , $x in $t_x_y/s/text()
  1440
+      , $y in $t_x_y/o/text()
  1441
+  for  $p in sem:ev1(  $sem:QN-O, (sem:query-p( $sem:P-OWL-ON-PROPERTY ), sem:query-s( $x )) ) 
  1442
+  for  $u in sem:ev1(  $sem:QN-S, (sem:query-p( $p ), sem:query-o( $x )) ) 
  1443
+  let $key := sem:uri-for-tuple($u, $sem:P-RDF-TYPE, $x, '')
  1444
+  where ( (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1445
+  return map:put(
  1446
+      $m, 
  1447
+      $key,   
  1448
+      sem:tuple($u, $sem:P-RDF-TYPE, $x, '')) 
  1449
+};
  1450
+
  1451
+
  1452
+
  1453
+(: owl2rl | cax-sco | subClassOf inference :)
  1454
+declare function sem:inf-owl2rl-cax-sco()
  1455
+as xs:integer
  1456
+{
  1457
+  let $m := map:map()
  1458
+  let $query := sem:inf-owl2rl-cax-sco($m)
  1459
+  let $exec := sem:inf-tuple-insert($m)
  1460
+  return map:count($m)
  1461
+};
  1462
+
  1463
+declare private function sem:inf-owl2rl-cax-sco($m as map:map)
  1464
+as  empty-sequence()
  1465
+{
  1466
+  for  $t_c1_c2 in sem:evT( sem:query-p( $sem:P-RDF-SUBCLASS ) ) 
  1467
+      , $c1 in $t_c1_c2/s/text()
  1468
+      , $c2 in $t_c1_c2/o/text()
  1469
+  for  $x in sem:ev1( $sem:QN-S, (sem:query-o( $c1 ), sem:query-p( $sem:P-RDF-TYPE ) )) 
  1470
+  let $key := sem:uri-for-tuple($x, $sem:P-RDF-TYPE , $c2, '')
  1471
+  where ( ($c1 != $c2)  and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1472
+  return map:put(
  1473
+      $m, 
  1474
+      $key,   
  1475
+      sem:tuple($x, $sem:P-RDF-TYPE , $c2, '')) 
  1476
+};
  1477
+
  1478
+
  1479
+
  1480
+(: owl2rl | scm-cls | class inference  TODO PARTIAL only first of four possible triples are generated :)
  1481
+declare function sem:inf-owl2rl-scm-cls()
  1482
+as xs:integer
  1483
+{
  1484
+  let $m := map:map()
  1485
+  let $query := sem:inf-owl2rl-scm-cls($m)
  1486
+  let $exec := sem:inf-tuple-insert($m)
  1487
+  return map:count($m)
  1488
+};
  1489
+
  1490
+declare private function sem:inf-owl2rl-scm-cls($m as map:map)
  1491
+as  empty-sequence()
  1492
+{
  1493
+  for  $c in sem:ev1(  $sem:QN-S, (sem:query-p( $sem:P-RDF-TYPE ), sem:query-o( $sem:O-OWL-CLASS)) ) 
  1494
+  let $key := sem:uri-for-tuple($c, $sem:P-RDF-SUBCLASS, $c, '')
  1495
+  where ( (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1496
+  return map:put(
  1497
+      $m, 
  1498
+      $key,   
  1499
+      sem:tuple($c, $sem:P-RDF-SUBCLASS, $c, '')) 
  1500
+};
  1501
+
  1502
+
  1503
+
  1504
+(: owl2rl | scm-sco   | subClassOf :)
  1505
+declare function sem:inf-owl2rl-scm-sco()
  1506
+as xs:integer
  1507
+{
  1508
+  let $m := map:map()
  1509
+  let $query := sem:inf-owl2rl-scm-sco($m)
  1510
+  let $exec := sem:inf-tuple-insert($m)
  1511
+  return map:count($m)
  1512
+};
  1513
+
  1514
+declare private function sem:inf-owl2rl-scm-sco($m as map:map)
  1515
+as  empty-sequence()
  1516
+{
  1517
+  for  $t_x_y in sem:evT( sem:query-p( $sem:P-RDF-SUBCLASS ) ) 
  1518
+      , $x in $t_x_y/s/text()
  1519
+      , $y in $t_x_y/o/text()
  1520
+  for  $z in sem:ev1( $sem:QN-O, (sem:query-s( $y ), sem:query-p( $sem:P-RDF-SUBCLASS ) )) 
  1521
+  let $key := sem:uri-for-tuple($x, $sem:P-RDF-SUBCLASS, $z, '')
  1522
+  where ( ($x != $y) and ($y != $z)  and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1523
+  return map:put(
  1524
+      $m, 
  1525
+      $key,   
  1526
+      sem:tuple($x, $sem:P-RDF-SUBCLASS, $z, '')) 
  1527
+};
  1528
+
  1529
+
  1530
+
  1531
+(: owl2rl | scm-op | Property inference TODO PARTIAL only first of two possible triples are generated:)
  1532
+declare function sem:inf-owl2rl-scm-op()
  1533
+as xs:integer
  1534
+{
  1535
+  let $m := map:map()
  1536
+  let $query := sem:inf-owl2rl-scm-op($m)
  1537
+  let $exec := sem:inf-tuple-insert($m)
  1538
+  return map:count($m)
  1539
+};
  1540
+
  1541
+declare private function sem:inf-owl2rl-scm-op($m as map:map)
  1542
+as  empty-sequence()
  1543
+{
  1544
+  for  $p in sem:ev1(  $sem:QN-S, (sem:query-p( $sem:P-RDF-TYPE ), sem:query-o( $sem:O-OWL-OBJECT-PROPERTY)) ) 
  1545
+  let $key := sem:uri-for-tuple($p, $sem:P-RDF-SUBPROPERTY, $p, '')
  1546
+  where ( (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1547
+  return map:put(
  1548
+      $m, 
  1549
+      $key,   
  1550
+      sem:tuple($p, $sem:P-RDF-SUBPROPERTY, $p, '')) 
  1551
+};
  1552
+
  1553
+
  1554
+(: owl2rl | scm-dp | Property inference TODO PARTIAL only first of two possible triples are generated:)
  1555
+declare function sem:inf-owl2rl-scm-dp()
  1556
+as xs:integer
  1557
+{
  1558
+  let $m := map:map()
  1559
+  let $query := sem:inf-owl2rl-scm-dp($m)
  1560
+  let $exec := sem:inf-tuple-insert($m)
  1561
+  return map:count($m)
  1562
+};
  1563
+
  1564
+declare private function sem:inf-owl2rl-scm-dp($m as map:map)
  1565
+as  empty-sequence()
  1566
+{
  1567
+  for  $p in sem:ev1(  $sem:QN-S, (sem:query-p( $sem:P-RDF-TYPE ), sem:query-o( $sem:O-OWL-DATATYPE-PROPERTY)) ) 
  1568
+  let $key := sem:uri-for-tuple($p, $sem:P-RDF-SUBPROPERTY, $p, '')
  1569
+  where ( (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1570
+  return map:put(
  1571
+      $m, 
  1572
+      $key,   
  1573
+      sem:tuple($p, $sem:P-RDF-SUBPROPERTY, $p, '')) 
  1574
+};
  1575
+
  1576
+
  1577
+(: owl2rl | scm-spo   | subPropertyOf :)
  1578
+declare function sem:inf-owl2rl-scm-spo()
  1579
+as xs:integer
  1580
+{
  1581
+  let $m := map:map()
  1582
+  let $query := sem:inf-owl2rl-scm-spo($m)
  1583
+  let $exec := sem:inf-tuple-insert($m)
  1584
+  return map:count($m)
  1585
+};
  1586
+
  1587
+declare private function sem:inf-owl2rl-scm-spo($m as map:map)
  1588
+as  empty-sequence()
  1589
+{
  1590
+  for  $t_x_y in sem:evT( sem:query-p( $sem:P-RDF-SUBPROPERTY ) ) 
  1591
+      , $x in $t_x_y/s/text()
  1592
+      , $y in $t_x_y/o/text()
  1593
+  for  $z in sem:ev1( $sem:QN-O, (sem:query-s( $y ), sem:query-p( $sem:P-RDF-SUBPROPERTY ) )) 
  1594
+  let $key := sem:uri-for-tuple($x, $sem:P-RDF-SUBPROPERTY, $z, '')
  1595
+  where ( ($x != $y) and ($y != $z)  and (map:count($m) lt 10000) and ( not (fn:doc-available($key)) ) )
  1596
+  return map:put(
  1597
+      $m, 
  1598
+      $key,    
  1599
+      sem:tuple($x, $sem:P-RDF-SUBPROPERTY, $z, '')) 
  1600
+};
  1601
+

0 notes on commit 212cf5a

Please sign in to comment.
Something went wrong with that request. Please try again.