After imports all the code in jena is here.
public class famtree {
static final String inputfile
=("C://Users//km//Desktop//Project//protege//Module.owl");
public static void main(String[] args) {
// TODO Auto-generated method stub
OntDocumentManager mgr=new OntDocumentManager();
OntModelSpec spec=new OntModelSpec(OntModelSpec.OWL_DL_MEM);
spec.setDocumentManager(mgr);
OntModel m = ModelFactory.createOntologyModel(spec,null);
//use filemanager to open ontology from file system
InputStream in=FileManager.get().open(inputfile);
if (in==null)
{
throw new IllegalArgumentException("File" + inputfile + "not found");
}
m.read(in,"");
String querystring="PREFIX rr:<
http://www.semanticweb.org/kumar/ontologies/2015/5/untitled-ontology-22#>"
+ "SELECT ?var \n "
+ "WHERE {"
+ " ?var rr:studies rr:Course2 " + " }";
Query query=QueryFactory.create(querystring);
QueryExecution qe = QueryExecutionFactory.create(query, m);
try {
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query);
//System.out.println(querystring);
}
finally {
qe.close();
}
On Sat, Aug 22, 2015 at 12:35 PM, Andy Seaborne <[email protected]> wrote:
> Show the data.
> Show how you created the model.
>
> http://stackoverflow.com/help/mcve
>
> Andy
>
>
> On 22/08/15 12:15, kumar rohit wrote:
>
>> Student studies course, this is the statement. Individuals are Student1,
>> Student2, Student3(subjects) and Course2(object).
>> Student1, Student2, Student3 studies Course2 where some other students
>> studies course1.
>>
>> On Sat, Aug 22, 2015 at 12:09 PM, Chris Dollin <
>> [email protected]
>>
>>> wrote:
>>>
>>
>> On 08/22/2015 11:47 AM, kumar rohit wrote:
>>>
>>> This code only displays "Student1" where it suppose to display Student1,
>>>> student2 and student 3 as i made the ontology in Protege so.. In protege
>>>> it
>>>> displays all three but here in Jena its output is:
>>>> | var |
>>>> ===============
>>>> | rr:Student1 |
>>>>
>>>>
>>>> code is below
>>>>
>>>>
>>> Show the model and how you construct it.
>>>
>>>
>>>
>>> __________________________________________________________________
>>>> String querystring="PREFIX rr:<
>>>>
>>>> http://www.semanticweb.org/asadali/ontologies/2015/5/untitled-ontology-22#
>>>>
>>>>> "
>>>>>
>>>> + "SELECT ?var \n "
>>>> + "WHERE {"
>>>> + " ?var rr:studies rr:Course2 " + " }";
>>>> Query query=QueryFactory.create(querystring);
>>>> QueryExecution qe = QueryExecutionFactory.create(query, m);
>>>> try {
>>>> ResultSet results = qe.execSelect();
>>>> ResultSetFormatter.out(System.out, results, query);
>>>> //System.out.println(querystring);
>>>> }
>>>>
>>>>
>>>> Chris
>>>
>>>
>>
>