Contributed by Tong Zhao

Similar documents
Apache Jena Framework. Philippe Genoud Université Joseph Fourier Grenoble (France)

1 Performance test source code

Knowledge management: The Jena API. Mohamed Sellami Département INFormatique TELECOM SudParis

Knowledge Representation. Apache Jena Part II. Jan Pettersen Nytun, UiA

Today s Plan. 1 Repetition: RDF. 2 Jena: Basic Datastructures. 3 Jena: Inspecting Models. 4 Jena: I/O. 5 Example. 6 Jena: ModelFactory and ModelMaker

Knowledge Representation XII IKT437 Apache Jena Part III Div

Today s Plan. 1 Repetition: RDF. 2 Jena: Basic Datastructures. 3 Jena: Inspecting Models. 4 Jena: I/O. 5 Example. 6 Jena: ModelFactory and ModelMaker

Orchestrating Music Queries via the Semantic Web

Programming THE SEMANTIC WEB. Build an application upon Semantic Web models. Brief overview of Apache Jena and OWL-API.

Semantic Web. Lecture 12: SW Programming Dr. Knarig Arabshian

CISC 3115 TY3. C24a: Lists. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 11/15/2018 CUNY Brooklyn College

JENA: A Java API for Ontology Management

Notes on access restrictions

Abstract Data Types (ADTs) Example ADTs. Using an Abstract Data Type. Class #08: Linear Data Structures

The XML PDF Access API for Java Technology (XPAAJ)

Extracting knowledge from Ontology using Jena for Semantic Web

PROGRAMMING FUNDAMENTALS

COMPUTER AND INFORMATION SCIENCE JENA DB. Group Abhishek Kumar Harshvardhan Singh Abhisek Mohanty Suhas Tumkur Chandrashekhara

The Collections API. Lecture Objectives. The Collections API. Mark Allen Weiss

Java Collections Framework: Interfaces

Using RDF to Model the Structure and Process of Systems

CHAPTER 1 INTRODUCTION

1)Write a program on inheritance and check weather the given object is instance of a class or not?

Search EECS /57

Stacks and Queues. David Greenstein Monta Vista

COSC 123 Computer Creativity. Java Lists and Arrays. Dr. Ramon Lawrence University of British Columbia Okanagan

Strings and Arrays. Hendrik Speleers

Generics. IRS W-9 Form

Alternate Methods for Informatica Metadata Exchange SDK

Semantic Integration with Apache Jena and Apache Stanbol

The Semantic Web Revisited. Nigel Shadbolt Tim Berners-Lee Wendy Hall

A Semantic Web-Based Approach for Harvesting Multilingual Textual. definitions from Wikipedia to support ICD-11 revision

Methods. Every Java application must have a main method.

An Architecture For RDF Storing And Querying For Messages

Semantic Web Test

An overview of RDB2RDF techniques and tools

a paradigm for the Introduction to Semantic Web Semantic Web Angelica Lo Duca IIT-CNR Linked Open Data:

Introduction to Trees. D. Thiebaut CSC212 Fall 2014

Computational Expression

CS111: PROGRAMMING LANGUAGE II

CO Java SE 8: Fundamentals

DB2 NoSQL Graph Store

Semantic Web Information Management

Simple Data Source Crawler Plugin to Set the Document Title

A Formal Definition of RESTful Semantic Web Services. Antonio Garrote Hernández María N. Moreno García

An Introduction to the Semantic Web. Jeff Heflin Lehigh University

Grid Resources Search Engine based on Ontology

Programming with the SCA BB Service Configuration API

Finding Similarity and Comparability from Merged Hetero Data of the Semantic Web by Using Graph Pattern Matching

Enterprise Information Integration using Semantic Web Technologies:

Welcome to INFO216: Advanced Modelling

1. Introduction. Lecture Content

Introduction to Programming Using Java (98-388)

OWL-DBC The Arrival of Scalable and Tractable OWL Reasoning for Enterprise Knowledge Bases

The Semantically Enabled Smart Grid

Lesson 26: ArrayList (W08D1)

SQream Connector JDBC SQream Technologies Version 2.9.3

CSCI-142 Exam 2 Review November 2, 2018 Presented by the RIT Computer Science Community

Development of guidelines for publishing statistical data as linked open data

What is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one

The MEG Metadata Schemas Registry Schemas and Ontologies: building a Semantic Infrastructure for GRIDs and digital libraries Edinburgh, 16 May 2003

Table of Contents. iii

Java Simple Data Types

geospatial querying ApacheCon Big Data Europe 2015 Budapest, 28/9/2015

Interfaces, collections and comparisons

CS1083 Week 2: Arrays, ArrayList

COMP9321 Web Application Engineering

CSE431 Translation of Computer Languages

Modern Trends in Semantic Web

COL106: Data Structures and Algorithms. Ragesh Jaiswal, IIT Delhi

Lists. CSC212 Lecture 8 D. Thiebaut, Fall 2014

Java Basic Programming Constructs

Structure of This Presentation

Semantic Technologies and CDISC Standards. Frederik Malfait, Information Architect, IMOS Consulting Scott Bahlavooni, Independent

Package rrdf. R topics documented: February 15, Type Package

DBpedia-An Advancement Towards Content Extraction From Wikipedia

Scaling the Semantic Wall with AllegroGraph and TopBraid Composer. A Joint Webinar by TopQuadrant and Franz

Controls Structure for Repetition

Full file at

Tirgul 1. Course Guidelines. Packages. Special requests. Inner classes. Inner classes - Example & Syntax

Programming with the SCA BB Service Configuration API

WICKED COOL JAVA. Code Bits, Open-Source Libraries, and Project Ideas. by Brian D. Eubanks. San Francisco

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Programming with the SCA BB Service Configuration API

Highlights of Previous Lecture

CS2113 Lab: Collections 10/29/2018

Readme file for Oracle Spatial and Graph and OBIEE Sample Application (V305) VirtualBox

Building Blocks of Linked Data

RDF Graph. for Oracle NoSQL Database. 12c Release 1

Question 1a) Trace of program

Functors. 01/23/03 Lecture 5 1

MIT AITI Lecture 18 Collections - Part 1

Knowledge Representation VII - IKT507. SPARQL stands for SPARQL Protocol And RDF Query Language

CIS 265 Exam 2 First Name Last Name

Abstract Data Types. Data Str. Client Prog. Add. Rem. Find. Show. 01/22/04 Lecture 4 1

B4M36DS2, BE4M36DS2: Database Systems 2

The HPCC JAVA APIs Project. Boca Raton Documentation Team

Proposal for Implementing Linked Open Data on Libraries Catalogue

CS Week 11. Jim Williams, PhD

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Transcription:

Chapter 1 Apache Jena Contributed by Tong Zhao 1.1 Background Apache Jena [3] is a free and open source Java specifically for building Semantic Web and Linked Data applications. Apache Jena provides an Java API that supports reading, writing and manipulating Resource Description Framework (RDF) graphs, where RDF is a set of World Wide Web Consortium (W3C) specifications [1] designed as a metadata data model. Jena was created by HP Labs 1 in the year of 2000. In 2009, HP decided to stop direct support of development of Jena, so the project team applied to have Jena adopted by the Apache Software Foundation in November 2010 and the vote result is still publicly available 2. 1.2 Expressing Graphs In Jena, an RDF graph is represented by a data structure called Model. A Model contains a collection of RDF resources (vertices), attached to each other by labelled relations (edges). Each relationship goes only in one direction, so all RDF graphs are directed and hence Jena does not support undirected graphs. Each resource can have any number of VCARD, which are the properties of that resource. The vcard Ontology [2] is predefined and contains a large number of property types. 1.3 Syntax Since Jena is a Java API, the syntax of Jena is just like any Java programs. Below is a small piece of code from Jena official documentations, the detailed meanings of the methods will be talked in the next section. // list the statements in the Model StmtIterator iter = model.liststatements(); // print out the predicate, subject and object of each statement 1 http://www8.hp.com/us/en/hp-labs/index.html 2 http://mail-archives.apache.org/mod mbox/incubator-general/201011.mbox/<4cec31e4.9080401@apache.org> 1

while (iter.hasnext()) { Statement stmt = iter.nextstatement(); // get next statement Resource subject = stmt.getsubject(); // get the subject Property predicate = stmt.getpredicate(); // get the predicate RDFNode object = stmt.getobject(); // get the object System.out.print(subject.toString()); System.out.print(" " + predicate.tostring() + " "); if (object instanceof Resource) { System.out.print(object.toString()); else { // object is a literal System.out.print(" \"" + object.tostring() + "\""); System.out.println("."); 1.4 Key Graph Primitives Model is the class that represents a graph in Jena API. To create a model, one can use a predefined model type in ModelFactory as: Model model = ModelFactory.createDefaultModel(); Resource is the class that represents a vertec in Jena API. Each resource usually have a URI as its unique id, so a resouce can be created as: static String personuri = "http://somewhere/johnsmith"; Resource johnsmith = model.createresource(personuri);.addproperty() is the method that can be used to add a property or a statement (edge) to a resourse. Taking the above resource johnsmith as an example, to add a property to it: static String fullname = "John Smith"; johnsmith.addproperty(vcard.fn, fullname); To make a statement between johnsmith with a new resource davidsmith: Resource davidsmith = model.createresource("http://somewhere/davidsmith"); johnsmith.addproperty(hasson, davidsmith);.liststatements() is the method to get a iterator which contains all the statements within the model. The example in Section 1.3 is using it to print out all the statements within a given model. SimpleSelector is a class that can be used to make basic queries on the model. Following is a basic example of it: // select all the resources with a VCARD.FN property // whose value ends with "Smith" StmtIterator iter = model.liststatements( new SimpleSelector(null, VCARD.FN, (RDFNode) null) { public boolean selects(statement s) {return s.getstring().endswith("smith"); Version 1.0 Page 2

); JenaARQTest, QueryFactory and QueryExecutionFactory are the classes that can be together used to execute any SPARQL queries on RDF graphs within the Java API, where SPARQL is a query language that was specifically designed for RDF databases. 1.5 Execution Model I did not find any description of Jena s execution model. 1.6 Examples Below is a basic BFS implementation 3 by Jena API in Java. import java.io.ioexception; import java.io.inputstream; import java.util.arraylist; import java.util.linkedlist; import java.util.list; import java.util.queue; import com.hp.hpl.jena.rdf.model.model; import com.hp.hpl.jena.rdf.model.modelfactory; import com.hp.hpl.jena.rdf.model.resource; import com.hp.hpl.jena.rdf.model.stmtiterator; import com.hp.hpl.jena.vocabulary.owl; import com.hp.hpl.jena.vocabulary.rdfs; public class BFSInRDFWithJena { public static List<List<Resource>> BFS( final Model model, final Queue<List<Resource>> queue, final int depth ) { final List<List<Resource>> results = new ArrayList<>(); while (!queue.isempty() ) { final List<Resource> path = queue.poll(); results.add( path ); if ( path.size() < depth ) { final Resource last = path.get( path.size() - 1 ); final StmtIterator stmt = model.liststatements(null, RDFS.subClassOf, last); while ( stmt.hasnext() ) { final List<Resource> extpath = new ArrayList<>( path ); extpath.add( stmt.next().getsubject().asresource() ); queue.offer( extpath ); 3 https://stackoverflow.com/questions/17750421/retrieving-all-paths-in-an-owl-class-hierarchy-with-sparql-andjena Version 1.0 Page 3

return results; public static void main( final String[] args ) throws IOException { final Model model = ModelFactory.createDefaultModel(); try (final InputStream in = BFSInRDFWithJena.class.getClassLoader(). getresourceasstream("camera.owl")) { model.read( in, null ); // setup the initial queue final Queue<List<Resource>> queue = new LinkedList<>(); final List<Resource> thingpath = new ArrayList<>(); thingpath.add( OWL.Thing ); queue.offer( thingpath ); // Get the paths, and display them final List<List<Resource>> paths = BFS( model, queue, 4 ); for ( List<Resource> path : paths ) { System.out.println( path ); 1.7 Conclusion Jena API is not like other graph paradigms like NetworkX 4 or SNAP 5, which are designed for graph algorithms. Jena was developed very specifically for building Semantic Web and Linked Data applications. In such applications, data are usually saved in RDF formatted databases and the resources usually have URI or URL. Jena can then take the advantage of working with or even querying RDF graphs within Java. 4 https://networkx.github.io/ 5 http://snap.stanford.edu/index.html Version 1.0 Page 4

Bibliography [1] Steve Bratt. Semantic web and other w3c technologies to watch. Talks at W3C, January, 2007. [2] Renato Iannella and James McKinney. vcard ontology-for describing people and organizations. W3C Group Note NOTE-vcard-rdf-20140522, 2014. [3] Apache Jena. Apache jena. jena. apache. org [Online]. Available: http://jena. apache. org [Accessed: Mar. 20, 2014], page 14, 2013. 5