java - how to return a detail information of URL/author from cidoc crm rdf file using sparql -
thank answer unfortunately not getting result in console, here attaching code, please guide making mistake.
filemanager.get().addlocatorclassloader(test.class.getclassloader()); model model=filemanager.get().loadmodel("h:/eclipseworkplace/museumdatabaserecommendation/src/data3.rdf"); string spr="prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"+ "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"+ "prefix crm: <urn:x-stackoverflow:example#>\n"+ "\n"+ "select * where{\n"+ " [ crm:e21_person/rdfs:label ?creator\n"+ " ; crm:p108i_was_produced_by [ crm:p126_employed [ rdfs:label ?material ]\n"+ " ; crm:p4_has_time-span [ crm:p82_at_some_time_within ?timespan ]\n"+ " ]\n"+ " ; crm:p3_has_note [ crm:p102_has_title\n"+ " ; rdfs:label ?title\n"+ " ]\n"+ " ]\n"+ " filter( ?creator = \"brett whiteley\" ).\n"+ "}"; query query = queryfactory.create(spr); //s2 = query above queryexecution qexe = queryexecutionfactory.create( query,model ); //queryexecution qexe = queryexecutionfactory.sparqlservice( "http://dbpedia.org/sparql", query ); resultset results = qexe.execselect(); resultsetformatter.out(system.out, results, query); my current output is
----------------------------------------- | creator | material | timespan | title | ========================================= ----------------------------------------- thanks time.
input data
in order facilitate readability, restructured model turtle syntax others read.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix crm: <http://www.cidoc-crm.org/cidoc-crm/> . <http://phdprototype.tk/collectionimage /4d0bff17-5810-4644-a550-d35ee090d4a8.png> "painting" ; rdfs:label "brett whiteley" ; crm:e21_person [ <e39_actor> ; rdfs:label "brett whiteley" ] ; crm:e62_string "painting\n" ; crm:p108i_was_produced_by [ crm:e12_production ; crm:p126_employed [ crm:e57_material ; rdfs:label "oil" ] ; crm:p4_has_time-span [ crm:e52_time-span ; crm:p82_at_some_time_within "\n 1976\n " ] ] ; crm:p3_has_note [ crm:p102_has_title ; rdfs:label "interior time past" ] ; crm:p7_took_place_at [ crm:e53_place ; crm:e44_place_appellation " \n 5d\n " ] ; crm:p91_has_unit [ crm:e58_measurement_unit ; rdfs:label "182.0 h * 200.0 w cm" ] . there issues data. example, painting has rdf:type plain literal "painting", extremely bad. denoted a "painting" property-object pair. can execute query on data, may wish restructure ontology uses terms rdf:type properly.
query
for sample data provided, following query extract looking for:
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix crm: <http://www.cidoc-crm.org/cidoc-crm/> select * where{ [ crm:e21_person/rdfs:label ?creator ; crm:p108i_was_produced_by [ crm:p126_employed [ rdfs:label ?material ] ; crm:p4_has_time-span [ crm:p82_at_some_time_within ?timespan ] ] ; crm:p3_has_note [ crm:p102_has_title ; rdfs:label ?title ] ] filter( ?creator = "brett whiteley" ). } will result in:
---------------------------------------------------------------------------------- | creator | material | timespan | title | ================================================================================== | "brett whiteley" | "oil" | "\n 1976\n " | "interior time past" | ---------------------------------------------------------------------------------- note highly tailored particular sample data. need adjust query match structures allowed. (hypothetical) example, timespan instance may have crm:p82_at_some_time_span property, or may have crm:exampleproperty relates values. in case, you'd need modify query use property path match this.
example code
public static final string querystring = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"+ "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"+ "prefix crm: <http://www.cidoc-crm.org/cidoc-crm/>\n"+ "\n"+ "select * where{\n"+ " [ crm:e21_person/rdfs:label ?creator\n"+ " ; crm:p108i_was_produced_by [ crm:p126_employed [ rdfs:label ?material ]\n"+ " ; crm:p4_has_time-span [ crm:p82_at_some_time_within ?timespan ]\n"+ " ]\n"+ " ; crm:p3_has_note [ crm:p102_has_title\n"+ " ; rdfs:label ?title\n"+ " ]\n"+ " ]\n"+ " filter( ?creator = \"brett whiteley\" ).\n"+ "}"; public static final query query = queryfactory.create(querystring); @test public void test() throws exception { final model model = modelfactory.createdefaultmodel(); try( final inputstream in = this.getclass().getresourceasstream("/so.rdf") ) { model.read(in, null, "rdf/xml"); } model.write(system.out, "ttl"); system.out.println("================================================================="); system.out.println(querystring); system.out.println("================================================================="); try( final queryexecution exec = queryexecutionfactory.create(query, model) ) { resultsetformatter.out(system.out, exec.execselect(), query); } }
Comments
Post a Comment