1 / 11

Using Java in Linked Data Applications

Using Java in Linked Data Applications. Fuming Shih Oct 12. Java Libraries. Jena - Java API for semantic web applications Jastor – typesafe , Ontology Driven RDF Access from Java http:// jastor.sourceforge.net /. Jena.

mircea
Download Presentation

Using Java in Linked Data Applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using Java in Linked Data Applications Fuming Shih Oct 12

  2. Java Libraries • Jena - Java API for semantic web applications • Jastor – typesafe, Ontology Driven RDF Access from Java • http://jastor.sourceforge.net/

  3. Jena • Programmatic environment for RDF, RDFS and OWL, SPARQL and includes a rule-based inference engine. • Jena has : • Resource interface represent resources • Property interface  represent properties • Literal interface  represent literals • Model interface  represent graph

  4. Example code to create graph with jena // some definitions static String personURI = "http://somewhere/JohnSmith"; static String fullName = "John Smith"; // create an empty Model Model model = ModelFactory.createDefaultModel(); // create the resource Resource johnSmith = model.createResource(personURI); // add the property johnSmith.addProperty(VCARD.FN, fullName);

  5. Task today • Load Lalana’sfoaf file at http://www.csail.mit.edu/~lkagal/foaf • Extract her friends • Look at the friends’ FOAF files • See where they work • Use the workplace URI or the labels to query dbpedia for it’s location • Print a list of friends, their workplaces and where the workplaces are located

  6. Installation • Download JDK • Download and install Eclipse • Download Jena and Jastor library • Tuning your Eclipse • Create a java project • Append Jena & Jastor libraries to your classpath

  7. Code Model model = ModelFactory.createDefaultModel(); // read the RDF/XML file model.read("http://www.csail.mit.edu/~lkagal/foaf", null); Property p_friend = model.createProperty("http://xmlns.com/foaf/0.1/knows"); StmtIterator friends = model.listStatements(null, p_friend, (RDFNode)null); while(friends.hasNext()){ Resource friend = (Resource) (friends.nextStatement().getObject()); Model model_friend = ModelFactory.createDefaultModel(); try{ model_friend.read(friend.getURI(),null); StmtIteratorworkPages = model_friend.listStatements(null, workPlaceHomepage,(RDFNode) null); while(workPages.hasNext()){ String workPlace = workPages.nextStatement().getObject().toString(); queryWorkPlace(friend.getURI(), workPlace); ….

  8. From Protégé to Java Objects • From ontology engineering to writing Semantic Web application is not straightforward • Graph is fundamentally not intuitive to programmer • Save your time by choosing the right tools • But be aware that mapping from OO to ontology needs cares

  9. SW for JAVA Programmer • Using ontology to represent domain knowledge • Use protégé to create/import different domain ontologies • Mapping ontologies to JAVA classes • Use Jastor library to generates Java interfaces, implementations, factories, and listeners based on the properties and class hierarchies in the Web ontologies • Easier for non-Semantic Web java developer to make use of ontology Java Objects Mapping tool listener Operator iCal SIOC Tag FOAF Jena2 Platform (RDF model + Reasoning Engine + Persistence System) RDF DB Ontology files JAVA VM

  10. Code Create mapping JastorContextctx = new JastorContext(); ctx.addOntologyToGenerate(newFileInputStream("src/data/Tag.owl"), "http://www.mit.edu/dig/ns/tag", "edu.mit.dig.model.Tag"); JastorGeneratorgen = new JastorGenerator( new File("gensrc").getCanonicalFile(), ctx); gen.run(); Make use of the class Tag tag = edu.mit.dig.model.Tag.tagFactory.createTag(NS_PREFIX + "id_1", model); tag.addName("A tag"); tag.addX(45); tag.addY(32);

  11. Demo

More Related