Permalink
Browse files

fixed bugs in translation

  • Loading branch information...
1 parent 6c48115 commit b0e17ce8e5ac74b3f8d9f87acc3e5d0ebd63d7ab @lidingpku lidingpku committed Apr 21, 2011
View
@@ -22,8 +22,6 @@
<classpathentry kind="lib" path="lib/pellet2.2.2/jena/icu4j-3.4.4.jar"/>
<classpathentry kind="lib" path="lib/pellet2.2.2/jena/iri-0.8-sources.jar"/>
<classpathentry kind="lib" path="lib/pellet2.2.2/jena/iri-0.8.jar"/>
- <classpathentry kind="lib" path="lib/pellet2.2.2/jena/jena-2.6.3-tests.jar"/>
- <classpathentry kind="lib" path="lib/pellet2.2.2/jena/jena-2.6.3.jar"/>
<classpathentry kind="lib" path="lib/pellet2.2.2/jena/junit-4.5.jar"/>
<classpathentry kind="lib" path="lib/pellet2.2.2/jena/log4j-1.2.13.jar"/>
<classpathentry kind="lib" path="lib/pellet2.2.2/jena/lucene-core-2.3.1.jar"/>
@@ -35,8 +33,10 @@
<classpathentry kind="lib" path="lib/pellet2.2.2/jena/xercesImpl-2.7.1.jar"/>
<classpathentry kind="lib" path="lib/pellet2.2.2/xsdlib/relaxngDatatype.jar"/>
<classpathentry kind="lib" path="lib/pellet2.2.2/xsdlib/xsdlib.jar"/>
- <classpathentry kind="lib" path="lib/pellet2.2.2/jena/arq-2.8.4.jar"/>
<classpathentry kind="lib" path="lib/sw4j-0.6.jar"/>
<classpathentry kind="lib" path="lib/marklogic-xcc-4.2.3.jar"/>
+ <classpathentry kind="lib" path="lib/pellet2.2.2/jena/arq-2.8.4.jar"/>
+ <classpathentry kind="lib" path="lib/pellet2.2.2/jena/jena-2.6.3-tests.jar"/>
+ <classpathentry kind="lib" path="lib/pellet2.2.2/jena/jena-2.6.3.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -1,17 +1,17 @@
# bakesale-query-34: list persons who are socially related to bake sale sellers
# and show which source suggested such relation
-prefix c: <http://lod-apps.googlecode.com/svn/trunk/data/bakesale/bs-ontology.ttl#>
-prefix p: <http://lod-apps.googlecode.com/svn/trunk/data/bakesale/bs-ontology.ttl#>
-prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
-select distinct ?g ?person ?p ?seller
-where {
- ?person a c:Person .
- ?seller a c:Person .
- ?person p:social_relation ?seller.
- ?event a c:Bake_Sale_Event .
- ?event p:seller ?seller .
- ?event p:product [a c:Cookie] .
- ?p rdfs:subPropertyOf p:social_relation .
- GRAPH ?g { {?person ?p ?seller .} UNION {?seller ?p ?person} }
+PREFIX c: <http://lod-apps.googlecode.com/svn/trunk/data/bakesale/bs-ontology.ttl#>
+PREFIX p: <http://lod-apps.googlecode.com/svn/trunk/data/bakesale/bs-ontology.ttl#>
+PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+SELECT distinct ?g ?person ?p ?seller
+WHERE {
+ ?person a c:Person .
+ ?seller a c:Person .
+ ?person p:social_relation ?seller.
+ ?event a c:Bake_Sale_Event .
+ ?event p:seller ?seller .
+ ?event p:product [a c:Cookie] .
+ ?p rdfs:subPropertyOf p:social_relation .
+ GRAPH ?g { {?person ?p ?seller .} UNION {?seller ?p ?person} }
}
@@ -1117,3 +1117,112 @@ as xs:string*
)
};
+
+
+(:------------------------------------------------:)
+(: Forward-Chaining Inference :)
+(:------------------------------------------------:)
+
+(: Forward-Chaining Inference -- general :)
+declare function sem:inf-tuple-insert($m as map:map)
+as empty-sequence()
+{
+ for $key in map:keys($m)
+ return xdmp:document-insert($key, map:get($m, $key))
+};
+
+declare function sem:inf-owl2rl(){
+ let $m := map:map()
+ let $query := (
+ sem:inf-owl2rl-eq-sym($m),
+ sem:inf-owl2rl-eq-trans($m),
+ sem:inf-owl2rl-eq-rep-s($m),
+ ()
+ )
+ let $cnt_new := map:count($m)
+ let $cnt_original := count(/t)
+ let $insert := sem:inf-tuple-insert($m)
+ let $cnt_inserted := count(/t) - $cnt_original
+ let $ret := (
+ if ($cnt_inserted>0)
+ then text { 'sem:inf-owl2rl -- triples to insert:', $cnt_new, '; triples inserted:', $cnt_inserted }
+ else () )
+ return $ret
+};
+
+
+(: Forward-Chaining Inference -- rules :)
+
+(: owl2rl | eq-sym | sameAs :)
+declare function sem:inf-owl2rl-eq-sym($m as map:map)
+as empty-sequence()
+{
+ for $t_x_y in sem:evT( sem:query-p( 'http://www.w3.org/2002/07/owl#sameAs' ) )
+ , $x in $t_x_y/s/text()
+ , $y in $t_x_y/o/text()
+ where ($x != $y)
+ return map:put(
+ $m,
+ sem:uri-for-tuple($y, 'http://www.w3.org/2002/07/owl#sameAs', $x, ''),
+ sem:tuple($y, 'http://www.w3.org/2002/07/owl#sameAs', $x, ''))
+};
+
+
+
+(: owl2rl | eq-trans | sameAs :)
+declare function sem:inf-owl2rl-eq-trans($m as map:map)
+as empty-sequence()
+{
+ for $t_x_y in sem:evT( sem:query-p( 'http://www.w3.org/2002/07/owl#sameAs' ) )
+ , $x in $t_x_y/s/text()
+ , $y in $t_x_y/o/text()
+ for $z in sem:ev1( $sem:QN-S, (sem:query-s( $y ), sem:query-p( 'http://www.w3.org/2002/07/owl#sameAs' ) ))
+ where ($x != $y) and ($y != $z)
+ return map:put(
+ $m,
+ sem:uri-for-tuple($x, 'http://www.w3.org/2002/07/owl#sameAs', $z, ''),
+ sem:tuple($x, 'http://www.w3.org/2002/07/owl#sameAs', $z, ''))
+};
+
+
+
+(: owl2rl | eq-rep-s | sameAs :)
+declare function sem:inf-owl2rl-eq-rep-s($m as map:map)
+as empty-sequence()
+{
+ for $t_x_y in sem:evT( sem:query-p( 'http://www.w3.org/2002/07/owl#sameAs' ) )
+ , $x in $t_x_y/s/text()
+ , $y in $t_x_y/o/text()
+ for $t_p_o in sem:evT( sem:query-s( $x ) )
+ , $p in $t_p_o/p/text()
+ , $o in $t_p_o/o/text()
+ where ($x != $y)
+ return map:put(
+ $m,
+ sem:uri-for-tuple($y, $p, $o, ''),
+ sem:tuple($y, $p, $o, ''))
+};
+
+
+(:------------------------------------------------:)
+(: Set operators :)
+(:------------------------------------------------:)
+declare function sem:setop-distinct-element($seq as element()*, $m as map:map) {
+ for $e in $seq
+ return map:put($m, $e,$e)
+};
+
+declare function sem:setop-distinct-element($seq as element()*) {
+ let $m := map:map()
+ let $x := sem:setop-distinct-element($seq, $m)
+ for $y in map:keys($m)
+ return map:get($m,$y)
+};
+
+declare function sem:setop-intersect($m as map:map, $seq1 as element()*, $seq2 as element()*) {
+ for $e1 in $seq1
+ for $e2 in $seq2
+ where deep-equal($e1,$e2)
+ return map:put($m, $e1,$e1)
+};
+
@@ -26,8 +26,8 @@
/*********************************************
* config
*/
- //String connectionUri = "xcc://admin:admin@localhost:8006/bakesale-full";
- String connectionUri = "xcc://admin:admin@ec2-184-73-4-47.compute-1.amazonaws.com:8005/bakesale";
+ String connectionUri = "xcc://admin:admin@localhost:8006/bakesale-test";
+ //String connectionUri = "xcc://admin:admin@ec2-184-73-4-47.compute-1.amazonaws.com:8005/bakesale";
public static void main(String [] args){
new ExampleBakesale().run();
@@ -76,10 +76,21 @@ public void printDebubInfo(){
if (null!=m_map_query_sparql_result){
String szResults_sparql = m_map_query_sparql_result.get(szQuery).toString();
System.out.println(String.format("[sparql results: %d]", countResults(szResults_sparql)));
+
String szResults_xquery = this.m_map_query_xquery_result.get(szQuery);
if (null!=szResults_xquery){
System.out.println(String.format("[xquery results: %d]", countResults(szResults_xquery)));
+/*
+ System.out.println("-----------------");
+ System.out.println(szQuerySparql);
+ System.out.println("-----------------");
+ System.out.println(szResults_sparql.replaceAll("</binding>\\s+<binding", "").replaceAll("http://lod-apps.googlecode.com/svn/trunk/data/bakesale/", ""));
+ System.out.println("-----------------");
+ System.out.println(szQueryXquery);
+ System.out.println("-----------------");
+ System.out.println(szResults_xquery.replaceAll("</binding>\\s+<binding", "").replaceAll("http://lod-apps.googlecode.com/svn/trunk/data/bakesale/", ""));
+*/
}
}
@@ -10,8 +10,8 @@
public class Test {
public static void main(String [] args){
- //String connectionUri = "xcc://admin:admin@localhost:8005/bakesale";
- String connectionUri = "xcc://admin:admin@ec2-184-73-4-47.compute-1.amazonaws.com:8005/bakesale";
+ String connectionUri = "xcc://admin:admin@localhost:8006/bakesale-test";
+ //String connectionUri = "xcc://admin:admin@ec2-184-73-4-47.compute-1.amazonaws.com:8005/bakesale";
ToolMarkLogicQueryRunner cq;
try {
cq = new ToolMarkLogicQueryRunner(new URI(connectionUri));
@@ -109,17 +109,8 @@ public void visit(ElementUnion el) {
log(el.getClass());
log(el);
}
+ //TODO
- ArrayList<S2XElementVisitor> branch = createBranch();
- for (Element e: el.getElements()){
- S2XElementVisitor visitor = new S2XElementVisitor();
- // copy context
- visitor.debug = this.debug;
- visitor.m_current_graph = this.m_current_graph;
-
- branch.add(visitor);
- e.visit(visitor);
- }
}
@Override
@@ -139,8 +130,37 @@ public void visit(ElementGroup el) {
log(el);
}
- for (Element e : el.getElements()){
- e.visit(this);
+ boolean isUnionGroup =false;
+ List<Element> children = el.getElements();
+ if (children.size()>1){
+ isUnionGroup =true;
+ for (int i=1; i<children.size(); i++){
+ if (!( children.get(i) instanceof ElementUnion)){
+ isUnionGroup =false;
+ break;
+ }
+ }
+ }
+
+ if (isUnionGroup){
+ ArrayList<S2XElementVisitor> branch = createBranch();
+ for (Element e: el.getElements()){
+ S2XElementVisitor visitor = new S2XElementVisitor();
+ if (e instanceof ElementUnion)
+ e= ((ElementUnion)e).getElements().get(0);
+
+ // copy context
+ visitor.debug = this.debug;
+ visitor.m_current_graph = this.m_current_graph;
+
+ branch.add(visitor);
+ e.visit(visitor);
+ }
+
+ }else{
+ for (Element e : el.getElements()){
+ e.visit(this);
+ }
}
}
@@ -226,7 +246,6 @@ public void visit(ElementSubQuery el) {
@Override
public String getFinalResults(List<String> resultsVars) {
// use recursion to enumerate all possible queries caused by union
-
ArrayList<String> ret = new ArrayList<String>();
ArrayList<ArrayList<S2XElementVisitor>> paths = getPaths();
@@ -250,7 +269,9 @@ public String getFinalResults(List<String> resultsVars) {
}
}
}
- }else{
+ }
+
+ {
ret.add( String.format("(: #total paths = %d :)",paths.size()));
ret.add( "import module namespace sem=\"http://marklogic.com/semantic\" at \"semantic.xqy\";" );
ret.add("");
@@ -278,6 +299,11 @@ public String getFinalResults(List<String> resultsVars) {
ret.add("};\n");
}
+ // path_id indicate max number of paths
+ {
+ ret.add("sem:setop-distinct-element (");
+ }
+
ret.add("(");
for (int i=1; i<=path_id; i++){
String szFunctionName = String.format("local:uf_%d",i);
@@ -287,6 +313,10 @@ public String getFinalResults(List<String> resultsVars) {
ret.add(szFunctionName+"()");
}
ret.add(")");
+
+ {
+ ret.add(")");
+ }
}
@@ -5,6 +5,7 @@
import org.apache.log4j.Logger;
+import com.hp.hpl.jena.sparql.expr.E_LogicalAnd;
import com.hp.hpl.jena.sparql.expr.Expr;
import com.hp.hpl.jena.sparql.expr.ExprFunction;
import com.hp.hpl.jena.sparql.expr.ExprFunctionOp;
@@ -194,8 +195,28 @@ public void visit(ExprVar arg0) {
@Override
public void visit(ExprFunction arg0) {
- // TODO Auto-generated method stub
+ if (m_expr_and.isEmpty()){
+ m_expr_and.add(arg0);
+ }
+ if (debug){
+ log("--- --- --- ---");
+ log(arg0.getClass());
+ log(arg0);
+
+ log(arg0.getFunctionSymbol());
+ }
+ boolean canDecompose = false;
+ if (arg0 instanceof E_LogicalAnd){
+ canDecompose = m_expr_and.remove(arg0);
+ }
+
+ for (Expr arg: arg0.getArgs()){
+ if (canDecompose){
+ this.m_expr_and.add(arg);
+ }
+ arg.visit(this);
+ }
}
}
Oops, something went wrong.

0 comments on commit b0e17ce

Please sign in to comment.