Hello All,
Apologies If I don't do this right but I am new to java and jena so please
bear with me if I am doing this wrong completely. I just started to get
back into coding after being away for some time. I've made an ontology but
I was wondering If It is possible to use SPARQL to pull in everything and
then use a rule to help filter the data and make it unique. Any advice or
help would be really appreciated
public static String reasoningTest() {
Model model = ModelFactory.createDefaultModel();
String rules = "[rule1:(if possible?)]";
Instant start = Instant.now();
Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
InfModel inf = ModelFactory.createInfModel(reasoner, model);
String queryString = "select ?o (min(?s)) " +
"where { ?s untitled-ontology-2:isRelatedToConcept ?o }" +
" GROUP BY ?o";;
Query query = QueryFactory.create(queryString);
try (QueryExecution qexec = QueryExecutionFactory.create(query, inf)) {
ResultSet results = qexec.execSelect();
for ( ; results.hasNext() ; ) {
QuerySolution soln = results.nextSolution();
System.out.println(soln.toString());
}
}
Instant end = Instant.now();
System.out.println("Sparql query " + queryString + " evaluated
in " + Duration.between(start, end));
}
The example would come out to be something like |s
|o |
| untitled-ontology-2:Recursion | untitled-ontology-2:Exercise5-2 |
| untitled-ontology-2:Proposition | untitled-ontology-2:Exercise1-1 |
| untitled-ontology-2:Congruence | untitled-ontology-2:Exercise4-2 |
| untitled-ontology-2:Sequence | untitled-ontology-2:Exercise2-2 |
| untitled-ontology-2:Function | untitled-ontology-2:Exercise2-2 |
| untitled-ontology-2:Predicate | untitled-ontology-2:Exercise1-1 |
| untitled-ontology-2:Set | untitled-ontology-2:Exercise2-1 |
| untitled-ontology-2:Induction | untitled-ontology-2:Exercise5-1 |
Some snippet of the ont is <owl:NamedIndividual
rdf:about="http://www.semanticweb.org/ontologies/2021/5/untitled-ontology-2#Predicate">
<rdf:type
rdf:resource="http://www.semanticweb.org/ontologies/2021/5/untitled-ontology-2#Concept"/></owl:NamedIndividual>
<owl:NamedIndividual
rdf:about="http://www.semanticweb.org/ontologies/2021/5/untitled-ontology-2#Exercise1-1">
<rdf:type
rdf:resource="http://www.semanticweb.org/ontologies/2021/5/untitled-ontology-2#Exercise"/>
<untitled-ontology-2:isRelatedToConcept
rdf:resource="http://www.semanticweb.org
/ontologies/2021/5/untitled-ontology-2#Predicate"/>
<untitled-ontology-2:isRelatedToConcept
rdf:resource="http://www.semanticweb.org
/ontologies/2021/5/untitled-ontology-2#Proposition"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://www.semanticweb.org
/ontologies/2021/5/untitled-ontology-2#Exercise1-2">
<rdf:type rdf:resource="http://www.semanticweb.org
/ontologies/2021/5/untitled-ontology-2#Exercise"/>
<untitled-ontology-2:isRelatedToConcept
rdf:resource="http://www.semanticweb.org
/ontologies/2021/5/untitled-ontology-2#Predicate"/></owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://www.semanticweb.org
/ontologies/2021/5/untitled-ontology-2#Exercise2-1">
<rdf:type rdf:resource="http://www.semanticweb.org
/ontologies/2021/5/untitled-ontology-2#Exercise"/>
<untitled-ontology-2:isRelatedToConcept
rdf:resource="http://www.semanticweb.org
/ontologies/2021/5/untitled-ontology-2#Set"/></owl:NamedIndividual>
in TTL format if needed
http://www.semanticweb.org/ontologies/2021/5/untitled-ontology-2#Structures:Structures
rdf:type owl:NamedIndividual ,:Course ;
:hasConcept :Congruence ,
:Function ,
:Induction ,
:Predicate ,
:Proposition ,
:Recursion ,
:Sequence ,
:Set ;
:hasTopic :BaseBExpansion ,
:TimeComplexity.
Any advice or help would be really appreciated needed any help tips
anything really would be greatly appreciated!
Thanks for everything,
On Thu, Jul 22, 2021 at 12:37 PM Brian Le <[email protected]> wrote:
> Hello All,
> Apologies If I don't do this right but I am new to java and jena so please
> bear with me if I am doing this wrong completely. I just started to get
> back into coding after being away for some time. I've made an ontology but
> I was wondering If It is possible to use SPARQL to pull in everything and
> then use a rule to help filter the data and make it unique. Any advice or
> help would be really appreciated
>
> public static String reasoningTest() {
>
> Model model = ModelFactory.createDefaultModel();
> String rules = "[rule1:(if possible?)]";
> Instant start = Instant.now();
> Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
> InfModel inf = ModelFactory.createInfModel(reasoner, model);
>
> String queryString = "select ?o (min(?s)) " +
> "where { ?s untitled-ontology-2:isRelatedToConcept ?o }" +
> " GROUP BY ?o";;
>
> Query query = QueryFactory.create(queryString);
>
> try (QueryExecution qexec = QueryExecutionFactory.create(query, inf))
> {
> ResultSet results = qexec.execSelect();
> for ( ; results.hasNext() ; ) {
> QuerySolution soln = results.nextSolution();
> System.out.println(soln.toString());
> }
> }
> Instant end = Instant.now();
> System.out.println("Sparql query " + queryString + " evaluated in " +
> Duration.between(start, end));
> }
>
> The example would come out to be something like |s
> |o |
>
> | untitled-ontology-2:Recursion | untitled-ontology-2:Exercise5-2 |
> | untitled-ontology-2:Proposition | untitled-ontology-2:Exercise1-1 |
> | untitled-ontology-2:Congruence | untitled-ontology-2:Exercise4-2 |
> | untitled-ontology-2:Sequence | untitled-ontology-2:Exercise2-2 |
> | untitled-ontology-2:Function | untitled-ontology-2:Exercise2-2 |
> | untitled-ontology-2:Predicate | untitled-ontology-2:Exercise1-1 |
> | untitled-ontology-2:Set | untitled-ontology-2:Exercise2-1 |
> | untitled-ontology-2:Induction | untitled-ontology-2:Exercise5-1 |
>
> Some snippet of the ont is <owl:NamedIndividual
> rdf:about="http://www.semanticweb.org/ontologies/2021/5/untitled-ontology-2#Predicate">
>
> <rdf:type
> rdf:resource="http://www.semanticweb.org/ontologies/2021/5/untitled-ontology-2#Concept"/></owl:NamedIndividual>
> <owl:NamedIndividual
> rdf:about="http://www.semanticweb.org/ontologies/2021/5/untitled-ontology-2#Exercise1-1">
> <rdf:type
> rdf:resource="http://www.semanticweb.org/ontologies/2021/5/untitled-ontology-2#Exercise"/>
> <untitled-ontology-2:isRelatedToConcept
> rdf:resource="http://www.semanticweb.org
> /ontologies/2021/5/untitled-ontology-2#Predicate"/>
> <untitled-ontology-2:isRelatedToConcept
> rdf:resource="http://www.semanticweb.org
> /ontologies/2021/5/untitled-ontology-2#Proposition"/>
> </owl:NamedIndividual>
>
> <owl:NamedIndividual rdf:about="http://www.semanticweb.org
> /ontologies/2021/5/untitled-ontology-2#Exercise1-2">
> <rdf:type rdf:resource="http://www.semanticweb.org
> /ontologies/2021/5/untitled-ontology-2#Exercise"/>
> <untitled-ontology-2:isRelatedToConcept
> rdf:resource="http://www.semanticweb.org
> /ontologies/2021/5/untitled-ontology-2#Predicate"/></owl:NamedIndividual>
> <owl:NamedIndividual rdf:about="http://www.semanticweb.org
> /ontologies/2021/5/untitled-ontology-2#Exercise2-1">
> <rdf:type rdf:resource="http://www.semanticweb.org
> /ontologies/2021/5/untitled-ontology-2#Exercise"/>
> <untitled-ontology-2:isRelatedToConcept
> rdf:resource="http://www.semanticweb.org
> /ontologies/2021/5/untitled-ontology-2#Set"/></owl:NamedIndividual>
>
> in TTL format if needed
>
> http://www.semanticweb.org/ontologies/2021/5/untitled-ontology-2#Structures:Structures
> rdf:type owl:NamedIndividual ,:Course ;
> :hasConcept :Congruence ,
> :Function ,
> :Induction ,
> :Predicate ,
> :Proposition ,
> :Recursion ,
> :Sequence ,
> :Set ;
> :hasTopic :BaseBExpansion ,
>
> :TimeComplexity.
>
>
> Any advice or help would be really appreciated needed any help tips
>
> anything really would be greatly appreciated!
>
>
> Thanks for everything,
>
>