SlideShare a Scribd company logo
Scalable and Reactive
Programming for Semantic
Web Developers
Jean-Paul Calbimonte
LSIR EPFL
Developers Workshop. Extended Semantic Web Conference ESWC 2015
Portoroz, 31.05.2015
@jpcik
Semantic Web Devs
2
Have fun
Love challenges
Need cool tools
Sesame
Scala: Functions and Objects
3
JVM language
Both object and functional oriented
Easy Java-interop
Reuse Java libraries
Growing community
RDF in Jena: in Scala
String personURI = "http://somewhere/JohnSmith";
Model model = ModelFactory.createDefaultModel();
model.createResource(personURI).addProperty(VCARD.FN,"John Smith");
Type inference
Not too useful
; and ()
4
Terser & compact code
Type-safe DSL
Compiler takes care
val personURI = "http://somewhere/JohnSmith"
val model = ModelFactory.createDefaultModel
model.createResource(personURI).addProperty(VCARD.FN,"John Smith")
sw:JohnSmith “John Smith”
vcard:FN
val personURI = "http://somewhere/JohnSmith"
implicit val model = createDefaultModel
add(personURI,VCARD.FN->"John Smith")
boilerplate
String converted
to Resource
Some more RDF
5
String personURI = "http://somewhere/JohnSmith";
String givenName = "John";
String familyName = "Smith";
String fullName = givenName + " " + familyName;
Model model = ModelFactory.createDefaultModel();
model.createResource(personURI)
.addProperty(VCARD.FN,fullName)
.addProperty(VCARD.N,model.createResource()
.addProperty(VCARD.Given,givenName)
.addProperty(VCARD.Family,familyName));
val personURI = "http://somewhere/JohnSmith"
val givenName = "John"
val familyName = "Smith"
val fullName = s"$givenName $familyName"
implicit val model = createDefaultModel
add(personURI,VCARD.FN->fullName,
VCARD.N ->add(bnode,VCARD.Given -> givenName,
VCARD.Family->familyName))
sw:JohnSmith
“John Smith”
vcard:FN
_:n
“John”
“Smith”vcard:N
vcard:Given
vcard:Family
Blank node
Scala DSLs customizable
Predicate-objects are pairs
Some more RDF in Jena
6
implicit val m=createDefaultModel
val ex="http://example.org/"
val alice=iri(ex+"alice")
val bob=iri(ex+"bob")
val charlie=iri(ex+"charlie")
alice+(RDF.`type`->FOAF.Person,
FOAF.name->"Alice",
FOAF.mbox-
>iri("mailto:alice@example.org"),
FOAF.knows->bob,
FOAF.knows->charlie, FOAF.knows->bnode)
bob+ (FOAF.name->"Bob",
FOAF.knows->charlie)
charlie+(FOAF.name->"Charlie",
FOAF.knows->alice)
Still valid Jena RDF
You can do it even nicer
Exploring an RDF Graph
7
ArrayList<String> names=new ArrayList<String>();
NodeIterator iter=model.listObjectsOfProperty(VCARD.N);
while (iter.hasNext()){
RDFNode obj=iter.next();
if (obj.isResource())
names.add(obj.asResource()
.getProperty(VCARD.Family).getObject().toString());
else if (obj.isLiteral())
names.add(obj.asLiteral().getString());
}
val names=model.listObjectsOfProperty(VCARD.N).map{
case r:Resource=>
r.getProperty(VCARD.Family).obj.toString
case l:Literal=>
l.getString
}
Imperative iteration of collections
Type-based conditional execution
Type casting
Case type
Map applied to operators
8
Query with SPARQL
9
val queryStr = """select distinct ?Concept
where {[] a ?Concept} LIMIT 10"""
val query = sparql(queryStr)
query.serviceSelect("http://dbpedia.org/sparql").foreach{implicit qs=>
println(res("Concept").getURI)
}
val f=Future(query.serviceSelect("http://es.dbpedia.org/sparql")).fallbackTo(
Future(query.serviceSelect("http://dbpedia.org/sparql")))
f.recover{
case e=> println("Error "+e.getMessage)
}
f.map(_.foreach{implicit qs=>
println(res("Concept").getValue)
})
Remote SPARQL endpoint
Simplified access to
Query solutions
Futures: asnyc execution
Non blocking code
Fallback alternative execution
Actor Model
10
Actor
1
Actor
2
m
No shared mutable state
Avoid blocking operators
Lightweight objects
Loose coupling
communicate
through messages
mailbox
state
behavior
non-blocking response
send: fire-forget
Implementations: e.g. Akka for Java/Scala
Pare
nt
Actor
1
Supervision
hierarchy
Supervision
Actor
2
Actor
4
X
Actor
2
Act
or1
Act
or2
m
Act
or3
Act
or4
m
m
Remoting
Reactive Systems
Event-Driven
Jonas Boner. Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems. 2013.
Events:
reactto
ScalableLoad:
ResilientFailure:
ResponsiveUsers:
11
RDF Streams: Actors
12
val sys=ActorSystem.create("system")
val consumer=sys.actorOf(Props[RdfConsumer])
class Streamer extends StreamRDF{
override def triple(triple:Triple){
consumer ! triple
}
}
class RdfConsumer extends Actor{
def receive= {
case t:Triple =>
if (t.predicateMatches(RDF.‘type‘))
println(s"received triple $t")
}
RDF consumer
Actor receive method
Implements behavior
Message-passing model
RDF producer
Async message passing
Web RDF Services
13
GET /containers/:containerid/ org.rsp.ldp.ContainerApp.retrieve(containerid:String)
POST /containers/:containerid/ org.rsp.ldp.ContainerApp.add(containerid:String)
object ContainerApp extends Controller {
def retrieve(id:String) = Action.async {implicit request=>
val sw=new StringWriter
val statements=m.listStatements(iri(prefix+id+"/"),null,null)
val model=createDefaultModel
statements.foreach(i=>model.add(i))
model.write(sw, "TURTLE")
Future(Ok(sw.toString).as("text/turtle").withHeaders(
ETAG->tag,
ALLOW->"GET,POST"
))
}
Routing rules
Controller returns RDF async
OWLAPI: reasoning
14
val onto=mgr.createOntology
val artist=clazz(pref+"Artist")
val singer=clazz(pref +"Singer")
onto += singer subClassOf artist
val reasoner = new RELReasonerFactory.createReasoner(onto)
val elvis=ind(pref+"Elvis")
reasoner += elvis ofClass singer
reasoner.reclassify
reasoner.getIndividuals(artist) foreach{a=>
println(a.getRepresentativeElement.getIRI)
}
Creating OWL classes
Declaring class relationships
Declare instances
How is it done?
15
object OwlApiTips{
implicit class TrowlRelReasoner(reasoner:RELReasoner){
def += (axiom:OWLAxiom)= reasoner.add(Set(axiom)) }
implicit class OwlClassPlus(theClass:OWLClass){
def subClassOf(superclass:OWLClass)(implicit fac:OWLDataFactory)=
fac.getOWLSubClassOfAxiom(theClass, superclass) }
implicit class OwlOntologyPlus(onto:OWLOntology){
def += (axiom:OWLAxiom)(implicit mgr:OWLOntologyManager)=
mgr.addAxiom(onto, axiom) }
implicit class OwlIndividualPlus(ind:OWLIndividual){
def ofClass (theclass:OWLClass)(implicit fac:OWLDataFactory)=
fac.getOWLClassAssertionAxiom(theclass, ind) }
implicit def str2Iri(s:String):IRI=IRI.create(s)
object clazz{
def apply(iri:String)(implicit fac:OWLDataFactory)=
fac.getOWLClass(iri) }
object ind{
def apply(iri:String)(implicit fac:OWLDataFactory)=
fac.getOWLNamedIndividual(iri) } }
Muchas gracias!
Jean-Paul Calbimonte
LSIR EPFL
@jpcik

More Related Content

What's hot (20)

PPT
2008 11 13 Hcls Call
Jun Zhao
 
PDF
Why Scala Is Taking Over the Big Data World
Dean Wampler
 
PDF
WebTech Tutorial Querying DBPedia
Katrien Verbert
 
PDF
Linking the world with Python and Semantics
Tatiana Al-Chueyr
 
PDF
Semantic Integration with Apache Jena and Stanbol
All Things Open
 
PDF
The Materials Project - Combining Science and Informatics to Accelerate Mater...
University of California, San Diego
 
PDF
Martin Odersky - Evolution of Scala
Scala Italy
 
PDF
What To Leave Implicit
Martin Odersky
 
PDF
Querying Linked Data with SPARQL
Olaf Hartig
 
PPTX
SPARQL Cheat Sheet
LeeFeigenbaum
 
PDF
Java collections the force awakens
RichardWarburton
 
PPT
Scala Days San Francisco
Martin Odersky
 
PPTX
Apache Jena Elephas and Friends
Rob Vesse
 
PPTX
Semantic web meetup – sparql tutorial
AdonisDamian
 
PPT
Devoxx
Martin Odersky
 
PPTX
Information-Rich Programming in F# with Semantic Data
Steffen Staab
 
PPTX
Beyond shuffling - Strata London 2016
Holden Karau
 
PPTX
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
PDF
Collections forceawakens
RichardWarburton
 
2008 11 13 Hcls Call
Jun Zhao
 
Why Scala Is Taking Over the Big Data World
Dean Wampler
 
WebTech Tutorial Querying DBPedia
Katrien Verbert
 
Linking the world with Python and Semantics
Tatiana Al-Chueyr
 
Semantic Integration with Apache Jena and Stanbol
All Things Open
 
The Materials Project - Combining Science and Informatics to Accelerate Mater...
University of California, San Diego
 
Martin Odersky - Evolution of Scala
Scala Italy
 
What To Leave Implicit
Martin Odersky
 
Querying Linked Data with SPARQL
Olaf Hartig
 
SPARQL Cheat Sheet
LeeFeigenbaum
 
Java collections the force awakens
RichardWarburton
 
Scala Days San Francisco
Martin Odersky
 
Apache Jena Elephas and Friends
Rob Vesse
 
Semantic web meetup – sparql tutorial
AdonisDamian
 
Information-Rich Programming in F# with Semantic Data
Steffen Staab
 
Beyond shuffling - Strata London 2016
Holden Karau
 
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
Collections forceawakens
RichardWarburton
 

Viewers also liked (6)

PPT
Aturansinus
aan72
 
PDF
Take a Look at Akka+Java (English version)
GlobalLogic Ukraine
 
PDF
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Thomas Lockney
 
PPTX
RDF Stream Processing Tutorial: RSP implementations
Jean-Paul Calbimonte
 
PDF
Introduction to Scala for Java Developers
Michael Galpin
 
PPTX
Reactive Java (GeeCON 2014)
Tomasz Kowalczewski
 
Aturansinus
aan72
 
Take a Look at Akka+Java (English version)
GlobalLogic Ukraine
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Thomas Lockney
 
RDF Stream Processing Tutorial: RSP implementations
Jean-Paul Calbimonte
 
Introduction to Scala for Java Developers
Michael Galpin
 
Reactive Java (GeeCON 2014)
Tomasz Kowalczewski
 
Ad

Similar to Scala Programming for Semantic Web Developers ESWC Semdev2015 (20)

PPTX
Triplestore and SPARQL
Lino Valdivia
 
PDF
Adaptive Semantic Data Management Techniques for Federations of Endpoints
PlanetData Network of Excellence
 
PDF
RDF Seminar Presentation
Muntazir Mehdi
 
PPTX
A Little SPARQL in your Analytics
Dr. Neil Brittliff
 
PPTX
Consuming Linked Data 4/5 Semtech2011
Juan Sequeda
 
PDF
A Hands On Overview Of The Semantic Web
Shamod Lacoul
 
PDF
RDF and Java
Constantin Stan
 
PDF
Graph basedrdf storeforapachecassandra
Ravindra Ranwala
 
PDF
Eclipse RDF4J - Working with RDF in Java
Jeen Broekstra
 
PDF
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
Josef Petrák
 
PPTX
Enterprise knowledge graphs
Sören Auer
 
PDF
Reactive Web-Applications @ LambdaDays
Manuel Bernhardt
 
PDF
RDF: what and why plus a SPARQL tutorial
Jerven Bolleman
 
PDF
Web Spa
Constantin Stan
 
PDF
Event Sourcing - what could possibly go wrong?
Andrzej Ludwikowski
 
PDF
Two graph data models : RDF and Property Graphs
andyseaborne
 
PPTX
Knowledge Graph Introduction
Sören Auer
 
PDF
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Codemotion
 
PPTX
Practical Cross-Dataset Queries with SPARQL (Introduction)
Richard Cyganiak
 
PPT
Automating the Use of Web APIs through Lightweight Semantics
mmaleshkova
 
Triplestore and SPARQL
Lino Valdivia
 
Adaptive Semantic Data Management Techniques for Federations of Endpoints
PlanetData Network of Excellence
 
RDF Seminar Presentation
Muntazir Mehdi
 
A Little SPARQL in your Analytics
Dr. Neil Brittliff
 
Consuming Linked Data 4/5 Semtech2011
Juan Sequeda
 
A Hands On Overview Of The Semantic Web
Shamod Lacoul
 
RDF and Java
Constantin Stan
 
Graph basedrdf storeforapachecassandra
Ravindra Ranwala
 
Eclipse RDF4J - Working with RDF in Java
Jeen Broekstra
 
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
Josef Petrák
 
Enterprise knowledge graphs
Sören Auer
 
Reactive Web-Applications @ LambdaDays
Manuel Bernhardt
 
RDF: what and why plus a SPARQL tutorial
Jerven Bolleman
 
Event Sourcing - what could possibly go wrong?
Andrzej Ludwikowski
 
Two graph data models : RDF and Property Graphs
andyseaborne
 
Knowledge Graph Introduction
Sören Auer
 
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Codemotion
 
Practical Cross-Dataset Queries with SPARQL (Introduction)
Richard Cyganiak
 
Automating the Use of Web APIs through Lightweight Semantics
mmaleshkova
 
Ad

More from Jean-Paul Calbimonte (20)

PDF
Towards Collaborative Creativity in Persuasive Multi-agent Systems
Jean-Paul Calbimonte
 
PDF
A Platform for Difficulty Assessment and Recommendation of Hiking Trails
Jean-Paul Calbimonte
 
PDF
Stream reasoning agents
Jean-Paul Calbimonte
 
PPTX
Decentralized Management of Patient Profiles and Trajectories through Semanti...
Jean-Paul Calbimonte
 
PDF
Personal Data Privacy Semantics in Multi-Agent Systems Interactions
Jean-Paul Calbimonte
 
PPTX
RDF data validation 2017 SHACL
Jean-Paul Calbimonte
 
PPTX
SanTour: Personalized Recommendation of Hiking Trails to Health Pro files
Jean-Paul Calbimonte
 
PPTX
Multi-agent interactions on the Web through Linked Data Notifications
Jean-Paul Calbimonte
 
PPTX
The MedRed Ontology for Representing Clinical Data Acquisition Metadata
Jean-Paul Calbimonte
 
PPTX
Linked Data Notifications for RDF Streams
Jean-Paul Calbimonte
 
PPTX
Fundamentos de Scala (Scala Basics) (español) Catecbol
Jean-Paul Calbimonte
 
PPTX
Connecting Stream Reasoners on the Web
Jean-Paul Calbimonte
 
PPTX
Query Rewriting in RDF Stream Processing
Jean-Paul Calbimonte
 
PPTX
Toward Semantic Sensor Data Archives on the Web
Jean-Paul Calbimonte
 
PPTX
Detection of hypoglycemic events through wearable sensors
Jean-Paul Calbimonte
 
PPTX
RDF Stream Processing and the role of Semantics
Jean-Paul Calbimonte
 
PPTX
The Schema Editor of OpenIoT for Semantic Sensor Networks
Jean-Paul Calbimonte
 
PPTX
XGSN: An Open-source Semantic Sensing Middleware for the Web of Things
Jean-Paul Calbimonte
 
PPT
X-GSN in OpenIoT SummerSchool
Jean-Paul Calbimonte
 
PPTX
GSN Global Sensor Networks for Environmental Data Management
Jean-Paul Calbimonte
 
Towards Collaborative Creativity in Persuasive Multi-agent Systems
Jean-Paul Calbimonte
 
A Platform for Difficulty Assessment and Recommendation of Hiking Trails
Jean-Paul Calbimonte
 
Stream reasoning agents
Jean-Paul Calbimonte
 
Decentralized Management of Patient Profiles and Trajectories through Semanti...
Jean-Paul Calbimonte
 
Personal Data Privacy Semantics in Multi-Agent Systems Interactions
Jean-Paul Calbimonte
 
RDF data validation 2017 SHACL
Jean-Paul Calbimonte
 
SanTour: Personalized Recommendation of Hiking Trails to Health Pro files
Jean-Paul Calbimonte
 
Multi-agent interactions on the Web through Linked Data Notifications
Jean-Paul Calbimonte
 
The MedRed Ontology for Representing Clinical Data Acquisition Metadata
Jean-Paul Calbimonte
 
Linked Data Notifications for RDF Streams
Jean-Paul Calbimonte
 
Fundamentos de Scala (Scala Basics) (español) Catecbol
Jean-Paul Calbimonte
 
Connecting Stream Reasoners on the Web
Jean-Paul Calbimonte
 
Query Rewriting in RDF Stream Processing
Jean-Paul Calbimonte
 
Toward Semantic Sensor Data Archives on the Web
Jean-Paul Calbimonte
 
Detection of hypoglycemic events through wearable sensors
Jean-Paul Calbimonte
 
RDF Stream Processing and the role of Semantics
Jean-Paul Calbimonte
 
The Schema Editor of OpenIoT for Semantic Sensor Networks
Jean-Paul Calbimonte
 
XGSN: An Open-source Semantic Sensing Middleware for the Web of Things
Jean-Paul Calbimonte
 
X-GSN in OpenIoT SummerSchool
Jean-Paul Calbimonte
 
GSN Global Sensor Networks for Environmental Data Management
Jean-Paul Calbimonte
 

Recently uploaded (20)

PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
Hashing Introduction , hash functions and techniques
sailajam21
 
PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PPTX
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
PPTX
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
PPTX
Day2 B2 Best.pptx
helenjenefa1
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PPTX
Server Side Web Development Unit 1 of Nodejs.pptx
sneha852132
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Hashing Introduction , hash functions and techniques
sailajam21
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
Day2 B2 Best.pptx
helenjenefa1
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Design Thinking basics for Engineers.pdf
CMR University
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
Server Side Web Development Unit 1 of Nodejs.pptx
sneha852132
 

Scala Programming for Semantic Web Developers ESWC Semdev2015

  • 1. Scalable and Reactive Programming for Semantic Web Developers Jean-Paul Calbimonte LSIR EPFL Developers Workshop. Extended Semantic Web Conference ESWC 2015 Portoroz, 31.05.2015 @jpcik
  • 2. Semantic Web Devs 2 Have fun Love challenges Need cool tools Sesame
  • 3. Scala: Functions and Objects 3 JVM language Both object and functional oriented Easy Java-interop Reuse Java libraries Growing community
  • 4. RDF in Jena: in Scala String personURI = "http://somewhere/JohnSmith"; Model model = ModelFactory.createDefaultModel(); model.createResource(personURI).addProperty(VCARD.FN,"John Smith"); Type inference Not too useful ; and () 4 Terser & compact code Type-safe DSL Compiler takes care val personURI = "http://somewhere/JohnSmith" val model = ModelFactory.createDefaultModel model.createResource(personURI).addProperty(VCARD.FN,"John Smith") sw:JohnSmith “John Smith” vcard:FN val personURI = "http://somewhere/JohnSmith" implicit val model = createDefaultModel add(personURI,VCARD.FN->"John Smith") boilerplate String converted to Resource
  • 5. Some more RDF 5 String personURI = "http://somewhere/JohnSmith"; String givenName = "John"; String familyName = "Smith"; String fullName = givenName + " " + familyName; Model model = ModelFactory.createDefaultModel(); model.createResource(personURI) .addProperty(VCARD.FN,fullName) .addProperty(VCARD.N,model.createResource() .addProperty(VCARD.Given,givenName) .addProperty(VCARD.Family,familyName)); val personURI = "http://somewhere/JohnSmith" val givenName = "John" val familyName = "Smith" val fullName = s"$givenName $familyName" implicit val model = createDefaultModel add(personURI,VCARD.FN->fullName, VCARD.N ->add(bnode,VCARD.Given -> givenName, VCARD.Family->familyName)) sw:JohnSmith “John Smith” vcard:FN _:n “John” “Smith”vcard:N vcard:Given vcard:Family Blank node Scala DSLs customizable Predicate-objects are pairs
  • 6. Some more RDF in Jena 6 implicit val m=createDefaultModel val ex="http://example.org/" val alice=iri(ex+"alice") val bob=iri(ex+"bob") val charlie=iri(ex+"charlie") alice+(RDF.`type`->FOAF.Person, FOAF.name->"Alice", FOAF.mbox- >iri("mailto:[email protected]"), FOAF.knows->bob, FOAF.knows->charlie, FOAF.knows->bnode) bob+ (FOAF.name->"Bob", FOAF.knows->charlie) charlie+(FOAF.name->"Charlie", FOAF.knows->alice) Still valid Jena RDF You can do it even nicer
  • 7. Exploring an RDF Graph 7 ArrayList<String> names=new ArrayList<String>(); NodeIterator iter=model.listObjectsOfProperty(VCARD.N); while (iter.hasNext()){ RDFNode obj=iter.next(); if (obj.isResource()) names.add(obj.asResource() .getProperty(VCARD.Family).getObject().toString()); else if (obj.isLiteral()) names.add(obj.asLiteral().getString()); } val names=model.listObjectsOfProperty(VCARD.N).map{ case r:Resource=> r.getProperty(VCARD.Family).obj.toString case l:Literal=> l.getString } Imperative iteration of collections Type-based conditional execution Type casting Case type Map applied to operators
  • 8. 8
  • 9. Query with SPARQL 9 val queryStr = """select distinct ?Concept where {[] a ?Concept} LIMIT 10""" val query = sparql(queryStr) query.serviceSelect("http://dbpedia.org/sparql").foreach{implicit qs=> println(res("Concept").getURI) } val f=Future(query.serviceSelect("http://es.dbpedia.org/sparql")).fallbackTo( Future(query.serviceSelect("http://dbpedia.org/sparql"))) f.recover{ case e=> println("Error "+e.getMessage) } f.map(_.foreach{implicit qs=> println(res("Concept").getValue) }) Remote SPARQL endpoint Simplified access to Query solutions Futures: asnyc execution Non blocking code Fallback alternative execution
  • 10. Actor Model 10 Actor 1 Actor 2 m No shared mutable state Avoid blocking operators Lightweight objects Loose coupling communicate through messages mailbox state behavior non-blocking response send: fire-forget Implementations: e.g. Akka for Java/Scala Pare nt Actor 1 Supervision hierarchy Supervision Actor 2 Actor 4 X Actor 2 Act or1 Act or2 m Act or3 Act or4 m m Remoting
  • 11. Reactive Systems Event-Driven Jonas Boner. Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems. 2013. Events: reactto ScalableLoad: ResilientFailure: ResponsiveUsers: 11
  • 12. RDF Streams: Actors 12 val sys=ActorSystem.create("system") val consumer=sys.actorOf(Props[RdfConsumer]) class Streamer extends StreamRDF{ override def triple(triple:Triple){ consumer ! triple } } class RdfConsumer extends Actor{ def receive= { case t:Triple => if (t.predicateMatches(RDF.‘type‘)) println(s"received triple $t") } RDF consumer Actor receive method Implements behavior Message-passing model RDF producer Async message passing
  • 13. Web RDF Services 13 GET /containers/:containerid/ org.rsp.ldp.ContainerApp.retrieve(containerid:String) POST /containers/:containerid/ org.rsp.ldp.ContainerApp.add(containerid:String) object ContainerApp extends Controller { def retrieve(id:String) = Action.async {implicit request=> val sw=new StringWriter val statements=m.listStatements(iri(prefix+id+"/"),null,null) val model=createDefaultModel statements.foreach(i=>model.add(i)) model.write(sw, "TURTLE") Future(Ok(sw.toString).as("text/turtle").withHeaders( ETAG->tag, ALLOW->"GET,POST" )) } Routing rules Controller returns RDF async
  • 14. OWLAPI: reasoning 14 val onto=mgr.createOntology val artist=clazz(pref+"Artist") val singer=clazz(pref +"Singer") onto += singer subClassOf artist val reasoner = new RELReasonerFactory.createReasoner(onto) val elvis=ind(pref+"Elvis") reasoner += elvis ofClass singer reasoner.reclassify reasoner.getIndividuals(artist) foreach{a=> println(a.getRepresentativeElement.getIRI) } Creating OWL classes Declaring class relationships Declare instances
  • 15. How is it done? 15 object OwlApiTips{ implicit class TrowlRelReasoner(reasoner:RELReasoner){ def += (axiom:OWLAxiom)= reasoner.add(Set(axiom)) } implicit class OwlClassPlus(theClass:OWLClass){ def subClassOf(superclass:OWLClass)(implicit fac:OWLDataFactory)= fac.getOWLSubClassOfAxiom(theClass, superclass) } implicit class OwlOntologyPlus(onto:OWLOntology){ def += (axiom:OWLAxiom)(implicit mgr:OWLOntologyManager)= mgr.addAxiom(onto, axiom) } implicit class OwlIndividualPlus(ind:OWLIndividual){ def ofClass (theclass:OWLClass)(implicit fac:OWLDataFactory)= fac.getOWLClassAssertionAxiom(theclass, ind) } implicit def str2Iri(s:String):IRI=IRI.create(s) object clazz{ def apply(iri:String)(implicit fac:OWLDataFactory)= fac.getOWLClass(iri) } object ind{ def apply(iri:String)(implicit fac:OWLDataFactory)= fac.getOWLNamedIndividual(iri) } }