SPIN model to String of SPARQL

15 views
Skip to first unread message

Alireza Shahbazi

unread,
Apr 30, 2022, 9:13:47 AM4/30/22
to topbrai...@googlegroups.com
Hi everyone
I have been used https://github.com/spinrdf/spinrdf/blob/master/src-examples/org/topbraid/spin/examples/SPINParsingExample.java
to generate SpinRDFModel from  SPARQL code and back.
However, when I want to parse back SpinModel with original SPARQL codes with FILTER NOT EXISTS, it omits NOT Exists's elements. for Example :
CONSTRUCT
{
?a rdf:type ?x .
}
WHERE {
?a rdf:type ?x .
FILTER NOT EXISTS {?a rdf:type ?y .}
}

converts to spinModel correctly, but when I want to get toString() of spinQuery , it returns :

CONSTRUCT {
?a a ?x .
}
WHERE {
?a a ?x .
FILTER <http://spinrdf.org/sp#notExists>([]) .
}

Similarly, this happens with a normal filter and it returns:
FILTER <http://spinrdf.org/sp#eq>(?a, 3)
Or
FILTER <http://spinrdf.org/sp#gt>(?a, 3) 
Instead of
FILTER(?a=3)
Or
FILTER (?a>3) 


My code is :

root = getRootOf(spinModel);//root has been found correctly
StmtIterator list = spinModel.listStatements(root, ResourceFactory.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), (String) null);
        while (list.hasNext())  {
            Statement s = list.next();
            if (s.getObject().isResource() && s.getObject().asResource().equals(SP.CONSTRUCT))   {
                Construct spinQuery = s.getSubject().as(Construct.class);
                return spinQuery.toString();
            }
}

How to change my code to get the correct SPARQL code?
Reply all
Reply to author
Forward
0 new messages