SlideShare a Scribd company logo
1 of 34
Dr. Myungjin Lee
What is the Jena?
  a Java framework for building Semantic Web
  applications
  A Java API for RDF

  Developed by Brian McBride of HP
  Derived from SiRPAC API

  Can parse, create, and search RDF models
  Easy to use
the Jena Framework includes:
  an API for reading, processing and writing RDF data in XML, N
  -triples and Turtle formats;
  an ontology API for handling OWL and RDFS ontologies;
  a rule-based inference engine for reasoning with RDF and OW
  L data sources;
  stores to allow large numbers of RDF triples to be efficiently s
  tored on disk;
  a query engine compliant with the latest SPARQL specification
  servers to allow RDF data to be published to other application
  s using a variety of protocols, including SPARQL
What can we do?

                         User interface and applications

                                                Trust

                                        Proof

                            Unifying logic


            ARQ              Ontologies:           Rules:




                                                            Cryptography
             Querying:         OWL               RIF/SWRL
             SPARQL
                                    Taxonomies: RDFS



                            Jena(ARP)
                         Data interchange: RDF

                                 Syntax: XML
                            SDB + TDB
              Identifiers: URI
                                           Character set:
                                            UNICODE
Install and Run Jena
  Get package from
     http://www.apache.org/dist/jena/
  Unzip it
  Setup environments (CLASSPATH)
  Online documentation
     Tutorial
        http://jena.apache.org/documentation/index.html
     API Doc
        http://jena.apache.org/documentation/javadoc/
Resource Description Framework
  a general method for conceptual description or
  modeling of information, especially web resources
Graph and Model
 Graph
    a simpler Java API intended for extending Jena's
    functionality
 Model
    a rich Java API with many convenience methods for Java
    application developers
Nodes and Triples
                 Statement
                                       Resource


      Resource                         Property




                             Literal




                                            Model
Interface Hierarchy
Core Classes
  What is a Model?
     one RDF graph which is represented by the Model
     interface


          Ontology
                                     Model
          (RDF Graph)




                                 Jena Programming
                                      Interface
Core Classes
  ModelFactory Class
     methods for creating standard kinds of Model
  Model Interface
     creating resources, properties and literals and the S
     tatements
     adding statements
     removing statements from a model
     querying a model and set operations for combining
     models.
How to make Model
 read Methods
    Model read(String url, String base, String lang)
    Model read(InputStream in, String base, String lang)
    Model read(Reader reader, String base, String lang)


 Parameters
    base - the base uri to be used when converting relative
    URI's to absolute URI's
    lang - "RDF/XML", "N-TRIPLE", "TURTLE" (or "TTL") and
    "N3"
How to make Model
Model model = ModelFactory.createDefaultModel();
InputStream in = FileManager.get().open(“BadBoy.owl");
model.read(in, null, “RDF/XML”);
How to write Model
  write Methods
      Model write(OutputStream out, String lang, String base)
      Model write(Writer writer, String lang, String base)


model.write(System.out);
model.write(System.out, "N-TRIPLE");


String fn = “temp/test.xml”;
model.write(new PrintWriter(new FileOutputStream(fn)));
Interfaces related to nodes
  Resource Interface
     An RDF Resource


  Property Interface
     An RDF Property


  RDFNode Interface
     Interface covering RDF resources and literals
How to create nodes
  from Model Interface
    to create new nodes whose model is this model


  from ResourceFactory Class
    to create resources and properties are not associat
    ed with a user-modifiable model
Resource and Property
  Methods
      Resource createResource(String uri)
      Property createProperty(String uriref)


Resource s = model.createResource(“…”);
Property p = ResourceFactory.createProperty(“…”);
Literal
  Un-typed Literal
      Literal createLiteral(String v, String language)
      Literal createLiteral(String v, boolean wellFormed)


Literal l1 = model.createLiteral("chat", "en")
Literal l2 = model.createLiteral("<em>chat</em>", true);
Literal
  Typed Literal
       Literal createTypedLiteral(Object value)

Literal l = model.createTypedLiteral(new Integer(25));


    Java class     xsd type         Java class     xsd type
      Float          float             Byte           byte
     Double         double         BigInteger       integer
     Integer          int          BigDecimal      decimal
      Long           long            Boolean       Boolean
      Short          short            String         string
RDF Triple and Statement Interface
  RDF Triple (Statement)
     arc in an RDF Model
     asserts a fact about a resource
     consists of subject, predicate, and object
                      Triple
         Subject      Predicate    Object




         Resource     Property    RDFNode         Jena Programming
                                                  Interface
                    Statement
Interfaces related to triples
  Statement Interface
     represents a triple
     consists of Resource, Property, and RDFNode

  StmtIterator Interface
     a set of statements (triples)
Getting Triples
StmtIterator iter = model.listStatements();
while (iter.hasNext()) {
    Statement stmt      = iter.nextStatement();
    Resource subject    = stmt.getSubject();
    Property predicate = stmt.getPredicate();
    RDFNode   object    = stmt.getObject();
}
To list the ‘selected’ statements in the Model
// making nodes for query
Resource husband =
model.createResource("http://iwec.yonsei.ac.kr/family#MyungjinLee");
Property type =
model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");

// querying a model
StmtIterator iter = model.listStatements(husband, type, (RDFNode) null);
while (iter.hasNext()) {
    Statement stmt = iter.nextStatement();
    Resource subject = stmt.getSubject();
    Property predicate = stmt.getPredicate();
    RDFNode object = stmt.getObject();
    System.out.println(subject + " " + predicate + " " + object);
}
Add a relation of resource
Resource husband =
model.createResource("http://iwec.yonsei.ac.kr/family#MyungjinLe
e");
Property marry =
model.createProperty("http://iwec.yonsei.ac.kr/family#hasWife");
Resource wife =
model.createResource("http://iwec.yonsei.ac.kr/family#YejinSon");
husband.addProperty(marry, wife);
Ontologies and reasoning
   to derive additional truths about the concepts

Jena2 inference subsystem
   to allow a range of inference engines or reasoners to be
   plugged into Jena
   http://jena.sourceforge.net/inference/index.html
Transitive reasoner
     Provides support for storing and traversing class and property lattices. This
     implements just the transitive and reflexive properties of rdfs:subPropertyOf
     and rdfs:subClassOf.
RDFS rule reasoner
     Implements a configurable subset of the RDFS entailments.
OWL, OWL Mini, OWL Micro Reasoners
     A set of useful but incomplete implementation of the OWL/Lite subset of the
     OWL/Full language.
DAML micro reasoner
     Used internally to enable the legacy DAML API to provide minimal (RDFS scale)
     inferencing.
Generic rule reasoner
     A rule based reasoner that supports user defined rules. Forward chaining,
     tabled backward chaining and hybrid execution strategies are supported.
hasWife
                           Person
                                                                        inverseOf
type          subClassOf                subClassOf          type

                                                                   hasHusband
       Male                                  Female



       type                                          type




       Myungj               hasWife          Yejin
       in Lee                                Son
                           hasHusband
Jena OWL reasoners
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
InfModel infmodel = ModelFactory.createInfModel(reasoner,
model);
Property husband =
model.createProperty("http://www.semantics.kr/family#hasH
usband");
StmtIterator iterHusband = infmodel.listStatements(null,
husband, myungjin);
while (iterHusband.hasNext()) {
    Statement stmt = iterHusband.nextStatement();
    Resource subject = stmt.getSubject();
    Property predicate = stmt.getPredicate();
    RDFNode object = stmt.getObject();
    System.out.println(subject + " " + predicate + " " +
object);
}
If someone's husband is Myungjin Lee,
                                            she is a happy woman.

                                   subClassOf      Happy
                    Person
                                                   Woman
       subClassOf              subClassOf



Male                                Female
                                                     type


type                                        type




Myungj               hasWife        Yejin
in Lee                              Son
family.rules

1. @prefix base: <http://www.semantics.kr/family#>.

2. [HappyWoman:
        (?x rdf:type base:Female),
        (base:MyungjinLee base:hasWife ?x)
               -> (?x rdf:type base:HappyWoman)]
Resource configuration = model.createResource();
configuration.addProperty
        (ReasonerVocabulary.PROPruleMode, "forward");
configuration.addProperty
        (ReasonerVocabulary.PROPruleSet, "family.rules");
Reasoner domainReasoner =
GenericRuleReasonerFactory.theInstance().create(configuration);
InfModel domaininfmodel =
ModelFactory.createInfModel(domainReasoner, infmodel);
StmtIterator happyIter =
domaininfmodel.listStatements(wife, type, (RDFNode) null);
SPARQL(SPARQL Protocol and RDF Query Language)
   an RDF query language, that is, a query language for
   databases
   to retrieve and manipulate data stored in Resource
   Description Framework format

Simple Example
   PREFIX foaf: <http://xmlns.com/foaf/0.1/>
   SELECT ?name ?email
   WHERE {
                  ?person              rdf:type
          foaf:Person.
                  ?person              foaf:name      ?name.
                  ?person              foaf:mbox      ?email.
   }
family.sparql

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
PREFIX base: <http://www.semantics.kr/family#>

SELECT ?x
WHERE {
             ?x                       rdf:type         base:Female.
             base:MyungjinLee         base:hasWife     ?x.
}
try {
    // make a query string from SPARQL file
    FileReader fr = new FileReader("family.sparql");
    BufferedReader br = new BufferedReader(fr);
    StringBuffer queryString = new StringBuffer();
    String temp;
    while ((temp = br.readLine()) != null) {
        queryString.append(temp);
    }
    Query query = QueryFactory.create(queryString.toString());
    // create a object for query
    QueryExecution qexec = QueryExecutionFactory.create(query,
domaininfmodel);
        ResultSet results = qexec.execSelect(); // execute SPARQL query
        while(results.hasNext()) {
            QuerySolution soln = results.nextSolution();
            RDFNode r = soln.get("x"); // get a result
            System.out.println(r.toString());
        }
} catch (Exception e) {
    e.printStackTrace();
}

More Related Content

What's hot

Tutorial on Ontology editor: Protege
Tutorial on Ontology editor: Protege Tutorial on Ontology editor: Protege
Tutorial on Ontology editor: Protege Biswanath Dutta
 
Web ontology language (owl)
Web ontology language (owl)Web ontology language (owl)
Web ontology language (owl)Ameer Sameer
 
Introduction to RDF & SPARQL
Introduction to RDF & SPARQLIntroduction to RDF & SPARQL
Introduction to RDF & SPARQLOpen Data Support
 
Introduction to RDF
Introduction to RDFIntroduction to RDF
Introduction to RDFNarni Rajesh
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
Ontology In A Nutshell (version 2)
Ontology In A Nutshell (version 2)Ontology In A Nutshell (version 2)
Ontology In A Nutshell (version 2)Fabien Gandon
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseMike Dirolf
 
SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)Thomas Francart
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
 
Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialAdonisDamian
 
Introduction to JSX
Introduction to JSXIntroduction to JSX
Introduction to JSXMicah Wood
 
SPARQL 사용법
SPARQL 사용법SPARQL 사용법
SPARQL 사용법홍수 허
 
Spark Streaming | Twitter Sentiment Analysis Example | Apache Spark Training ...
Spark Streaming | Twitter Sentiment Analysis Example | Apache Spark Training ...Spark Streaming | Twitter Sentiment Analysis Example | Apache Spark Training ...
Spark Streaming | Twitter Sentiment Analysis Example | Apache Spark Training ...Edureka!
 

What's hot (20)

Tutorial on Ontology editor: Protege
Tutorial on Ontology editor: Protege Tutorial on Ontology editor: Protege
Tutorial on Ontology editor: Protege
 
Web ontology language (owl)
Web ontology language (owl)Web ontology language (owl)
Web ontology language (owl)
 
Introduction to RDF & SPARQL
Introduction to RDF & SPARQLIntroduction to RDF & SPARQL
Introduction to RDF & SPARQL
 
Json
JsonJson
Json
 
Introduction to RDF
Introduction to RDFIntroduction to RDF
Introduction to RDF
 
SHACL by example
SHACL by exampleSHACL by example
SHACL by example
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
RDF, linked data and semantic web
RDF, linked data and semantic webRDF, linked data and semantic web
RDF, linked data and semantic web
 
RDF data model
RDF data modelRDF data model
RDF data model
 
Ontology In A Nutshell (version 2)
Ontology In A Nutshell (version 2)Ontology In A Nutshell (version 2)
Ontology In A Nutshell (version 2)
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
ShEx vs SHACL
ShEx vs SHACLShEx vs SHACL
ShEx vs SHACL
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source Database
 
SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorial
 
Introduction to JSX
Introduction to JSXIntroduction to JSX
Introduction to JSX
 
SPARQL 사용법
SPARQL 사용법SPARQL 사용법
SPARQL 사용법
 
Spark Streaming | Twitter Sentiment Analysis Example | Apache Spark Training ...
Spark Streaming | Twitter Sentiment Analysis Example | Apache Spark Training ...Spark Streaming | Twitter Sentiment Analysis Example | Apache Spark Training ...
Spark Streaming | Twitter Sentiment Analysis Example | Apache Spark Training ...
 

Viewers also liked

PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel HordesPyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordeskgrandis
 
Face Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learnFace Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learnShiqiao Du
 
Face Recognition using OpenCV
Face Recognition using OpenCVFace Recognition using OpenCV
Face Recognition using OpenCVVasile Chelban
 
Semantic Web - Ontology 101
Semantic Web - Ontology 101Semantic Web - Ontology 101
Semantic Web - Ontology 101Luigi De Russis
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Luigi De Russis
 
Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Luigi De Russis
 

Viewers also liked (7)

PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel HordesPyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
 
Face Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learnFace Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learn
 
Java and OWL
Java and OWLJava and OWL
Java and OWL
 
Face Recognition using OpenCV
Face Recognition using OpenCVFace Recognition using OpenCV
Face Recognition using OpenCV
 
Semantic Web - Ontology 101
Semantic Web - Ontology 101Semantic Web - Ontology 101
Semantic Web - Ontology 101
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)
 
Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)
 

Similar to Jena Programming

RDF APIs for .NET Framework
RDF APIs for .NET FrameworkRDF APIs for .NET Framework
RDF APIs for .NET FrameworkAdriana Ivanciu
 
2009 Dils Flyweb
2009 Dils Flyweb2009 Dils Flyweb
2009 Dils FlywebJun Zhao
 
Sparql semantic information retrieval by
Sparql semantic information retrieval bySparql semantic information retrieval by
Sparql semantic information retrieval byIJNSA Journal
 
2008 11 13 Hcls Call
2008 11 13 Hcls Call2008 11 13 Hcls Call
2008 11 13 Hcls CallJun Zhao
 
Bio it 2005_rdf_workshop05
Bio it 2005_rdf_workshop05Bio it 2005_rdf_workshop05
Bio it 2005_rdf_workshop05Joanne Luciano
 
Semantic web
Semantic webSemantic web
Semantic webtariq1352
 
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIsJosef Petrák
 
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONS
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONSSPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONS
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONSIJNSA Journal
 
2010 03 Lodoxf Openflydata
2010 03 Lodoxf Openflydata2010 03 Lodoxf Openflydata
2010 03 Lodoxf OpenflydataJun Zhao
 
Rdf Processing On The Java Platform
Rdf Processing On The Java PlatformRdf Processing On The Java Platform
Rdf Processing On The Java Platformguestc1b16406
 
Hack U Barcelona 2011
Hack U Barcelona 2011Hack U Barcelona 2011
Hack U Barcelona 2011Peter Mika
 
Integrating a Domain Ontology Development Environment and an Ontology Search ...
Integrating a Domain Ontology Development Environment and an Ontology Search ...Integrating a Domain Ontology Development Environment and an Ontology Search ...
Integrating a Domain Ontology Development Environment and an Ontology Search ...Takeshi Morita
 
Java Training in Noida Delhi NCR BY Ducat
Java Training in Noida Delhi NCR BY DucatJava Training in Noida Delhi NCR BY Ducat
Java Training in Noida Delhi NCR BY DucatShri Prakash Pandey
 

Similar to Jena Programming (20)

RDF APIs for .NET Framework
RDF APIs for .NET FrameworkRDF APIs for .NET Framework
RDF APIs for .NET Framework
 
2009 Dils Flyweb
2009 Dils Flyweb2009 Dils Flyweb
2009 Dils Flyweb
 
Sparql semantic information retrieval by
Sparql semantic information retrieval bySparql semantic information retrieval by
Sparql semantic information retrieval by
 
2008 11 13 Hcls Call
2008 11 13 Hcls Call2008 11 13 Hcls Call
2008 11 13 Hcls Call
 
Bio it 2005_rdf_workshop05
Bio it 2005_rdf_workshop05Bio it 2005_rdf_workshop05
Bio it 2005_rdf_workshop05
 
Semantic web
Semantic webSemantic web
Semantic web
 
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
 
SWT Lecture Session 2 - RDF
SWT Lecture Session 2 - RDFSWT Lecture Session 2 - RDF
SWT Lecture Session 2 - RDF
 
RDF and Java
RDF and JavaRDF and Java
RDF and Java
 
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONS
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONSSPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONS
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONS
 
2010 03 Lodoxf Openflydata
2010 03 Lodoxf Openflydata2010 03 Lodoxf Openflydata
2010 03 Lodoxf Openflydata
 
Rdf Processing On The Java Platform
Rdf Processing On The Java PlatformRdf Processing On The Java Platform
Rdf Processing On The Java Platform
 
Semantic web
Semantic web Semantic web
Semantic web
 
Hack U Barcelona 2011
Hack U Barcelona 2011Hack U Barcelona 2011
Hack U Barcelona 2011
 
RDF validation tutorial
RDF validation tutorialRDF validation tutorial
RDF validation tutorial
 
Integrating a Domain Ontology Development Environment and an Ontology Search ...
Integrating a Domain Ontology Development Environment and an Ontology Search ...Integrating a Domain Ontology Development Environment and an Ontology Search ...
Integrating a Domain Ontology Development Environment and an Ontology Search ...
 
Java Training in Noida Delhi NCR BY Ducat
Java Training in Noida Delhi NCR BY DucatJava Training in Noida Delhi NCR BY Ducat
Java Training in Noida Delhi NCR BY Ducat
 
Jpl presentation
Jpl presentationJpl presentation
Jpl presentation
 
Jpl presentation
Jpl presentationJpl presentation
Jpl presentation
 
Jpl presentation
Jpl presentationJpl presentation
Jpl presentation
 

More from Myungjin Lee

지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)Myungjin Lee
 
JSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSPJSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSPMyungjin Lee
 
JSP 프로그래밍 #04 JSP 의 기본
JSP 프로그래밍 #04 JSP 의 기본JSP 프로그래밍 #04 JSP 의 기본
JSP 프로그래밍 #04 JSP 의 기본Myungjin Lee
 
JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿Myungjin Lee
 
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기Myungjin Lee
 
JSP 프로그래밍 #01 웹 프로그래밍
JSP 프로그래밍 #01 웹 프로그래밍JSP 프로그래밍 #01 웹 프로그래밍
JSP 프로그래밍 #01 웹 프로그래밍Myungjin Lee
 
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)Myungjin Lee
 
오픈 데이터와 인공지능
오픈 데이터와 인공지능오픈 데이터와 인공지능
오픈 데이터와 인공지능Myungjin Lee
 
법령 온톨로지의 구축 및 검색
법령 온톨로지의 구축 및 검색법령 온톨로지의 구축 및 검색
법령 온톨로지의 구축 및 검색Myungjin Lee
 
도서관과 Linked Data
도서관과 Linked Data도서관과 Linked Data
도서관과 Linked DataMyungjin Lee
 
공공데이터, 현재 우리는?
공공데이터, 현재 우리는?공공데이터, 현재 우리는?
공공데이터, 현재 우리는?Myungjin Lee
 
LODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data WorkshopLODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data WorkshopMyungjin Lee
 
Introduction of Deep Learning
Introduction of Deep LearningIntroduction of Deep Learning
Introduction of Deep LearningMyungjin Lee
 
쉽게 이해하는 LOD
쉽게 이해하는 LOD쉽게 이해하는 LOD
쉽게 이해하는 LODMyungjin Lee
 
서울시 열린데이터 광장 문화관광 분야 LOD 서비스
서울시 열린데이터 광장 문화관광 분야 LOD 서비스서울시 열린데이터 광장 문화관광 분야 LOD 서비스
서울시 열린데이터 광장 문화관광 분야 LOD 서비스Myungjin Lee
 
LOD(Linked Open Data) Recommendations
LOD(Linked Open Data) RecommendationsLOD(Linked Open Data) Recommendations
LOD(Linked Open Data) RecommendationsMyungjin Lee
 
Interlinking for Linked Data
Interlinking for Linked DataInterlinking for Linked Data
Interlinking for Linked DataMyungjin Lee
 
Linked Open Data Tutorial
Linked Open Data TutorialLinked Open Data Tutorial
Linked Open Data TutorialMyungjin Lee
 
Linked Data Usecases
Linked Data UsecasesLinked Data Usecases
Linked Data UsecasesMyungjin Lee
 
공공데이터와 Linked open data
공공데이터와 Linked open data공공데이터와 Linked open data
공공데이터와 Linked open dataMyungjin Lee
 

More from Myungjin Lee (20)

지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
 
JSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSPJSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSP
 
JSP 프로그래밍 #04 JSP 의 기본
JSP 프로그래밍 #04 JSP 의 기본JSP 프로그래밍 #04 JSP 의 기본
JSP 프로그래밍 #04 JSP 의 기본
 
JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿
 
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
 
JSP 프로그래밍 #01 웹 프로그래밍
JSP 프로그래밍 #01 웹 프로그래밍JSP 프로그래밍 #01 웹 프로그래밍
JSP 프로그래밍 #01 웹 프로그래밍
 
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
 
오픈 데이터와 인공지능
오픈 데이터와 인공지능오픈 데이터와 인공지능
오픈 데이터와 인공지능
 
법령 온톨로지의 구축 및 검색
법령 온톨로지의 구축 및 검색법령 온톨로지의 구축 및 검색
법령 온톨로지의 구축 및 검색
 
도서관과 Linked Data
도서관과 Linked Data도서관과 Linked Data
도서관과 Linked Data
 
공공데이터, 현재 우리는?
공공데이터, 현재 우리는?공공데이터, 현재 우리는?
공공데이터, 현재 우리는?
 
LODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data WorkshopLODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data Workshop
 
Introduction of Deep Learning
Introduction of Deep LearningIntroduction of Deep Learning
Introduction of Deep Learning
 
쉽게 이해하는 LOD
쉽게 이해하는 LOD쉽게 이해하는 LOD
쉽게 이해하는 LOD
 
서울시 열린데이터 광장 문화관광 분야 LOD 서비스
서울시 열린데이터 광장 문화관광 분야 LOD 서비스서울시 열린데이터 광장 문화관광 분야 LOD 서비스
서울시 열린데이터 광장 문화관광 분야 LOD 서비스
 
LOD(Linked Open Data) Recommendations
LOD(Linked Open Data) RecommendationsLOD(Linked Open Data) Recommendations
LOD(Linked Open Data) Recommendations
 
Interlinking for Linked Data
Interlinking for Linked DataInterlinking for Linked Data
Interlinking for Linked Data
 
Linked Open Data Tutorial
Linked Open Data TutorialLinked Open Data Tutorial
Linked Open Data Tutorial
 
Linked Data Usecases
Linked Data UsecasesLinked Data Usecases
Linked Data Usecases
 
공공데이터와 Linked open data
공공데이터와 Linked open data공공데이터와 Linked open data
공공데이터와 Linked open data
 

Recently uploaded

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Jena Programming

  • 2. What is the Jena? a Java framework for building Semantic Web applications A Java API for RDF Developed by Brian McBride of HP Derived from SiRPAC API Can parse, create, and search RDF models Easy to use
  • 3. the Jena Framework includes: an API for reading, processing and writing RDF data in XML, N -triples and Turtle formats; an ontology API for handling OWL and RDFS ontologies; a rule-based inference engine for reasoning with RDF and OW L data sources; stores to allow large numbers of RDF triples to be efficiently s tored on disk; a query engine compliant with the latest SPARQL specification servers to allow RDF data to be published to other application s using a variety of protocols, including SPARQL
  • 4. What can we do? User interface and applications Trust Proof Unifying logic ARQ Ontologies: Rules: Cryptography Querying: OWL RIF/SWRL SPARQL Taxonomies: RDFS Jena(ARP) Data interchange: RDF Syntax: XML SDB + TDB Identifiers: URI Character set: UNICODE
  • 5. Install and Run Jena Get package from http://www.apache.org/dist/jena/ Unzip it Setup environments (CLASSPATH) Online documentation Tutorial http://jena.apache.org/documentation/index.html API Doc http://jena.apache.org/documentation/javadoc/
  • 6. Resource Description Framework a general method for conceptual description or modeling of information, especially web resources
  • 7. Graph and Model Graph a simpler Java API intended for extending Jena's functionality Model a rich Java API with many convenience methods for Java application developers
  • 8. Nodes and Triples Statement Resource Resource Property Literal Model
  • 10. Core Classes What is a Model? one RDF graph which is represented by the Model interface Ontology Model (RDF Graph) Jena Programming Interface
  • 11. Core Classes ModelFactory Class methods for creating standard kinds of Model Model Interface creating resources, properties and literals and the S tatements adding statements removing statements from a model querying a model and set operations for combining models.
  • 12. How to make Model read Methods Model read(String url, String base, String lang) Model read(InputStream in, String base, String lang) Model read(Reader reader, String base, String lang) Parameters base - the base uri to be used when converting relative URI's to absolute URI's lang - "RDF/XML", "N-TRIPLE", "TURTLE" (or "TTL") and "N3"
  • 13. How to make Model Model model = ModelFactory.createDefaultModel(); InputStream in = FileManager.get().open(“BadBoy.owl"); model.read(in, null, “RDF/XML”);
  • 14. How to write Model write Methods Model write(OutputStream out, String lang, String base) Model write(Writer writer, String lang, String base) model.write(System.out); model.write(System.out, "N-TRIPLE"); String fn = “temp/test.xml”; model.write(new PrintWriter(new FileOutputStream(fn)));
  • 15. Interfaces related to nodes Resource Interface An RDF Resource Property Interface An RDF Property RDFNode Interface Interface covering RDF resources and literals
  • 16. How to create nodes from Model Interface to create new nodes whose model is this model from ResourceFactory Class to create resources and properties are not associat ed with a user-modifiable model
  • 17. Resource and Property Methods Resource createResource(String uri) Property createProperty(String uriref) Resource s = model.createResource(“…”); Property p = ResourceFactory.createProperty(“…”);
  • 18. Literal Un-typed Literal Literal createLiteral(String v, String language) Literal createLiteral(String v, boolean wellFormed) Literal l1 = model.createLiteral("chat", "en") Literal l2 = model.createLiteral("<em>chat</em>", true);
  • 19. Literal Typed Literal Literal createTypedLiteral(Object value) Literal l = model.createTypedLiteral(new Integer(25)); Java class xsd type Java class xsd type Float float Byte byte Double double BigInteger integer Integer int BigDecimal decimal Long long Boolean Boolean Short short String string
  • 20. RDF Triple and Statement Interface RDF Triple (Statement) arc in an RDF Model asserts a fact about a resource consists of subject, predicate, and object Triple Subject Predicate Object Resource Property RDFNode Jena Programming Interface Statement
  • 21. Interfaces related to triples Statement Interface represents a triple consists of Resource, Property, and RDFNode StmtIterator Interface a set of statements (triples)
  • 22. Getting Triples StmtIterator iter = model.listStatements(); while (iter.hasNext()) { Statement stmt = iter.nextStatement(); Resource subject = stmt.getSubject(); Property predicate = stmt.getPredicate(); RDFNode object = stmt.getObject(); }
  • 23. To list the ‘selected’ statements in the Model // making nodes for query Resource husband = model.createResource("http://iwec.yonsei.ac.kr/family#MyungjinLee"); Property type = model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); // querying a model StmtIterator iter = model.listStatements(husband, type, (RDFNode) null); while (iter.hasNext()) { Statement stmt = iter.nextStatement(); Resource subject = stmt.getSubject(); Property predicate = stmt.getPredicate(); RDFNode object = stmt.getObject(); System.out.println(subject + " " + predicate + " " + object); }
  • 24. Add a relation of resource Resource husband = model.createResource("http://iwec.yonsei.ac.kr/family#MyungjinLe e"); Property marry = model.createProperty("http://iwec.yonsei.ac.kr/family#hasWife"); Resource wife = model.createResource("http://iwec.yonsei.ac.kr/family#YejinSon"); husband.addProperty(marry, wife);
  • 25. Ontologies and reasoning to derive additional truths about the concepts Jena2 inference subsystem to allow a range of inference engines or reasoners to be plugged into Jena http://jena.sourceforge.net/inference/index.html
  • 26. Transitive reasoner Provides support for storing and traversing class and property lattices. This implements just the transitive and reflexive properties of rdfs:subPropertyOf and rdfs:subClassOf. RDFS rule reasoner Implements a configurable subset of the RDFS entailments. OWL, OWL Mini, OWL Micro Reasoners A set of useful but incomplete implementation of the OWL/Lite subset of the OWL/Full language. DAML micro reasoner Used internally to enable the legacy DAML API to provide minimal (RDFS scale) inferencing. Generic rule reasoner A rule based reasoner that supports user defined rules. Forward chaining, tabled backward chaining and hybrid execution strategies are supported.
  • 27. hasWife Person inverseOf type subClassOf subClassOf type hasHusband Male Female type type Myungj hasWife Yejin in Lee Son hasHusband
  • 28. Jena OWL reasoners Reasoner reasoner = ReasonerRegistry.getOWLReasoner(); InfModel infmodel = ModelFactory.createInfModel(reasoner, model); Property husband = model.createProperty("http://www.semantics.kr/family#hasH usband"); StmtIterator iterHusband = infmodel.listStatements(null, husband, myungjin); while (iterHusband.hasNext()) { Statement stmt = iterHusband.nextStatement(); Resource subject = stmt.getSubject(); Property predicate = stmt.getPredicate(); RDFNode object = stmt.getObject(); System.out.println(subject + " " + predicate + " " + object); }
  • 29. If someone's husband is Myungjin Lee, she is a happy woman. subClassOf Happy Person Woman subClassOf subClassOf Male Female type type type Myungj hasWife Yejin in Lee Son
  • 30. family.rules 1. @prefix base: <http://www.semantics.kr/family#>. 2. [HappyWoman: (?x rdf:type base:Female), (base:MyungjinLee base:hasWife ?x) -> (?x rdf:type base:HappyWoman)]
  • 31. Resource configuration = model.createResource(); configuration.addProperty (ReasonerVocabulary.PROPruleMode, "forward"); configuration.addProperty (ReasonerVocabulary.PROPruleSet, "family.rules"); Reasoner domainReasoner = GenericRuleReasonerFactory.theInstance().create(configuration); InfModel domaininfmodel = ModelFactory.createInfModel(domainReasoner, infmodel); StmtIterator happyIter = domaininfmodel.listStatements(wife, type, (RDFNode) null);
  • 32. SPARQL(SPARQL Protocol and RDF Query Language) an RDF query language, that is, a query language for databases to retrieve and manipulate data stored in Resource Description Framework format Simple Example PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?email WHERE { ?person rdf:type foaf:Person. ?person foaf:name ?name. ?person foaf:mbox ?email. }
  • 33. family.sparql PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . PREFIX base: <http://www.semantics.kr/family#> SELECT ?x WHERE { ?x rdf:type base:Female. base:MyungjinLee base:hasWife ?x. }
  • 34. try { // make a query string from SPARQL file FileReader fr = new FileReader("family.sparql"); BufferedReader br = new BufferedReader(fr); StringBuffer queryString = new StringBuffer(); String temp; while ((temp = br.readLine()) != null) { queryString.append(temp); } Query query = QueryFactory.create(queryString.toString()); // create a object for query QueryExecution qexec = QueryExecutionFactory.create(query, domaininfmodel); ResultSet results = qexec.execSelect(); // execute SPARQL query while(results.hasNext()) { QuerySolution soln = results.nextSolution(); RDFNode r = soln.get("x"); // get a result System.out.println(r.toString()); } } catch (Exception e) { e.printStackTrace(); }