Movatterモバイル変換


[0]ホーム

URL:


PPTX, PDF1,962 views

Scala Programming for Semantic Web Developers ESWC Semdev2015

Scalable and Reactive Programming for Semantic Web Developers discusses using Scala for semantic web development. Key points include:- Scala allows for more concise RDF code compared to Java through features like type inference and implicit parameters.- The actor model and futures in Scala enable asynchronous and reactive programming for RDF streams and SPARQL queries. - OWL API reasoning with ontologies can be done more clearly in Scala through implicit classes that simplify common operations.

Related topics:

Embed presentation

Downloaded 16 times
Scalable and ReactiveProgramming for SemanticWeb DevelopersJean-Paul CalbimonteLSIR EPFLDevelopers Workshop. Extended Semantic Web Conference ESWC 2015Portoroz, 31.05.2015@jpcik
Semantic Web Devs2Have funLove challengesNeed cool toolsSesame
Scala: Functions and Objects3JVM languageBoth object and functional orientedEasy Java-interopReuse Java librariesGrowing community
RDF in Jena: in ScalaString personURI = "http://somewhere/JohnSmith";Model model = ModelFactory.createDefaultModel();model.createResource(personURI).addProperty(VCARD.FN,"John Smith");Type inferenceNot too useful; and ()4Terser & compact codeType-safe DSLCompiler takes careval personURI = "http://somewhere/JohnSmith"val model = ModelFactory.createDefaultModelmodel.createResource(personURI).addProperty(VCARD.FN,"John Smith")sw:JohnSmith “John Smith”vcard:FNval personURI = "http://somewhere/JohnSmith"implicit val model = createDefaultModeladd(personURI,VCARD.FN->"John Smith")boilerplateString convertedto Resource
Some more RDF5String 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 = createDefaultModeladd(personURI,VCARD.FN->fullName,VCARD.N ->add(bnode,VCARD.Given -> givenName,VCARD.Family->familyName))sw:JohnSmith“John Smith”vcard:FN_:n“John”“Smith”vcard:Nvcard:Givenvcard:FamilyBlank nodeScala DSLs customizablePredicate-objects are pairs
Some more RDF in Jena6implicit val m=createDefaultModelval 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 RDFYou can do it even nicer
Exploring an RDF Graph7ArrayList<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.toStringcase l:Literal=>l.getString}Imperative iteration of collectionsType-based conditional executionType castingCase typeMap applied to operators
8
Query with SPARQL9val queryStr = """select distinct ?Conceptwhere {[] 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 endpointSimplified access toQuery solutionsFutures: asnyc executionNon blocking codeFallback alternative execution
Actor Model10Actor1Actor2mNo shared mutable stateAvoid blocking operatorsLightweight objectsLoose couplingcommunicatethrough messagesmailboxstatebehaviornon-blocking responsesend: fire-forgetImplementations: e.g. Akka for Java/ScalaParentActor1SupervisionhierarchySupervisionActor2Actor4XActor2Actor1Actor2mActor3Actor4mmRemoting
Reactive SystemsEvent-DrivenJonas Boner. Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems. 2013.Events:reacttoScalableLoad:ResilientFailure:ResponsiveUsers:11
RDF Streams: Actors12val 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 consumerActor receive methodImplements behaviorMessage-passing modelRDF producerAsync message passing
Web RDF Services13GET /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 StringWriterval statements=m.listStatements(iri(prefix+id+"/"),null,null)val model=createDefaultModelstatements.foreach(i=>model.add(i))model.write(sw, "TURTLE")Future(Ok(sw.toString).as("text/turtle").withHeaders(ETAG->tag,ALLOW->"GET,POST"))}Routing rulesController returns RDF async
OWLAPI: reasoning14val onto=mgr.createOntologyval artist=clazz(pref+"Artist")val singer=clazz(pref +"Singer")onto += singer subClassOf artistval reasoner = new RELReasonerFactory.createReasoner(onto)val elvis=ind(pref+"Elvis")reasoner += elvis ofClass singerreasoner.reclassifyreasoner.getIndividuals(artist) foreach{a=>println(a.getRepresentativeElement.getIRI)}Creating OWL classesDeclaring class relationshipsDeclare instances
How is it done?15object 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 CalbimonteLSIR EPFL@jpcik

Recommended

PDF
The Materials Project Ecosystem - A Complete Software and Data Platform for M...
PDF
Scala Days NYC 2016
PDF
Querying the Web of Data with XSPARQL 1.1
PPTX
RDF Stream Processing: Let's React
PPTX
Streams of RDF Events Derive2015
PPT
OrdRing 2013 keynote - On the need for a W3C community group on RDF Stream Pr...
PDF
RxJS - The Reactive Extensions for JavaScript
PDF
RDF Stream Processing Models (SR4LD2013)
PPT
Devoxx
PDF
WebTech Tutorial Querying DBPedia
PPT
Scala Days San Francisco
PDF
Martin Odersky - Evolution of Scala
PDF
Linking the world with Python and Semantics
PDF
Why Scala Is Taking Over the Big Data World
PPTX
Apache Jena Elephas and Friends
PPTX
SPARQL Cheat Sheet
PDF
What To Leave Implicit
PPTX
Semantic web meetup – sparql tutorial
PDF
Semantic Integration with Apache Jena and Stanbol
PDF
The Materials Project - Combining Science and Informatics to Accelerate Mater...
PDF
Java collections the force awakens
PDF
Collections forceawakens
PDF
Querying Linked Data with SPARQL
PPTX
Scala - The Simple Parts, SFScala presentation
PPT
2008 11 13 Hcls Call
PPTX
Beyond shuffling - Strata London 2016
PPTX
Information-Rich Programming in F# with Semantic Data
PDF
PDF
Take a Look at Akka+Java (English version)
PPTX
RDF Stream Processing Tutorial: RSP implementations

More Related Content

PDF
The Materials Project Ecosystem - A Complete Software and Data Platform for M...
PDF
Scala Days NYC 2016
PDF
Querying the Web of Data with XSPARQL 1.1
PPTX
RDF Stream Processing: Let's React
PPTX
Streams of RDF Events Derive2015
PPT
OrdRing 2013 keynote - On the need for a W3C community group on RDF Stream Pr...
PDF
RxJS - The Reactive Extensions for JavaScript
PDF
RDF Stream Processing Models (SR4LD2013)
The Materials Project Ecosystem - A Complete Software and Data Platform for M...
Scala Days NYC 2016
Querying the Web of Data with XSPARQL 1.1
RDF Stream Processing: Let's React
Streams of RDF Events Derive2015
OrdRing 2013 keynote - On the need for a W3C community group on RDF Stream Pr...
RxJS - The Reactive Extensions for JavaScript
RDF Stream Processing Models (SR4LD2013)

What's hot

PPT
Devoxx
PDF
WebTech Tutorial Querying DBPedia
PPT
Scala Days San Francisco
PDF
Martin Odersky - Evolution of Scala
PDF
Linking the world with Python and Semantics
PDF
Why Scala Is Taking Over the Big Data World
PPTX
Apache Jena Elephas and Friends
PPTX
SPARQL Cheat Sheet
PDF
What To Leave Implicit
PPTX
Semantic web meetup – sparql tutorial
PDF
Semantic Integration with Apache Jena and Stanbol
PDF
The Materials Project - Combining Science and Informatics to Accelerate Mater...
PDF
Java collections the force awakens
PDF
Collections forceawakens
PDF
Querying Linked Data with SPARQL
PPTX
Scala - The Simple Parts, SFScala presentation
PPT
2008 11 13 Hcls Call
PPTX
Beyond shuffling - Strata London 2016
PPTX
Information-Rich Programming in F# with Semantic Data
PDF
Devoxx
WebTech Tutorial Querying DBPedia
Scala Days San Francisco
Martin Odersky - Evolution of Scala
Linking the world with Python and Semantics
Why Scala Is Taking Over the Big Data World
Apache Jena Elephas and Friends
SPARQL Cheat Sheet
What To Leave Implicit
Semantic web meetup – sparql tutorial
Semantic Integration with Apache Jena and Stanbol
The Materials Project - Combining Science and Informatics to Accelerate Mater...
Java collections the force awakens
Collections forceawakens
Querying Linked Data with SPARQL
Scala - The Simple Parts, SFScala presentation
2008 11 13 Hcls Call
Beyond shuffling - Strata London 2016
Information-Rich Programming in F# with Semantic Data

Viewers also liked

PDF
Take a Look at Akka+Java (English version)
PPTX
RDF Stream Processing Tutorial: RSP implementations
PDF
Introduction to Scala for Java Developers
PPTX
Reactive Java (GeeCON 2014)
PDF
Reactive programming using rx java & akka actors - pdx-scala - june 2014
PPT
Aturansinus
 
Take a Look at Akka+Java (English version)
RDF Stream Processing Tutorial: RSP implementations
Introduction to Scala for Java Developers
Reactive Java (GeeCON 2014)
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Aturansinus
 

Similar to Scala Programming for Semantic Web Developers ESWC Semdev2015

PDF
Reactive Web-Applications @ LambdaDays
PDF
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
PPTX
Enterprise knowledge graphs
PDF
Two graph data models : RDF and Property Graphs
PDF
Eclipse RDF4J - Working with RDF in Java
PPTX
Knowledge Graph Introduction
PDF
RDF and Java
PDF
Event Sourcing - what could possibly go wrong?
PPTX
A Little SPARQL in your Analytics
PDF
Web Spa
PDF
A Hands On Overview Of The Semantic Web
PPT
Automating the Use of Web APIs through Lightweight Semantics
PDF
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
PPTX
Triplestore and SPARQL
PPTX
Consuming Linked Data 4/5 Semtech2011
PDF
Graph basedrdf storeforapachecassandra
PPTX
Practical Cross-Dataset Queries with SPARQL (Introduction)
PDF
Adaptive Semantic Data Management Techniques for Federations of Endpoints
PDF
RDF: what and why plus a SPARQL tutorial
PDF
RDF Seminar Presentation
Reactive Web-Applications @ LambdaDays
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Enterprise knowledge graphs
Two graph data models : RDF and Property Graphs
Eclipse RDF4J - Working with RDF in Java
Knowledge Graph Introduction
RDF and Java
Event Sourcing - what could possibly go wrong?
A Little SPARQL in your Analytics
Web Spa
A Hands On Overview Of The Semantic Web
Automating the Use of Web APIs through Lightweight Semantics
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
Triplestore and SPARQL
Consuming Linked Data 4/5 Semtech2011
Graph basedrdf storeforapachecassandra
Practical Cross-Dataset Queries with SPARQL (Introduction)
Adaptive Semantic Data Management Techniques for Federations of Endpoints
RDF: what and why plus a SPARQL tutorial
RDF Seminar Presentation

More from Jean-Paul Calbimonte

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

Recently uploaded

PPTX
Generative AI Deep Dive: Architectures, Mechanics, and Future Applications
PDF
PRIZ Academy - Thinking The Skill Everyone Forgot
PPTX
CEC369 IoT P CEC369 IoT P CEC369 IoT PCEC369 IoT PCEC369 IoT P
PPTX
Washing-Machine-Simulation-using-PICSimLab.pptx
PPTX
K-nearest neighbouring machine learing algorithm .pptx
PPTX
Blockchain and cryptography Lecture Notes
PPTX
31.03.24 - 7.CURRICULUM & TEACHING - LEARNING PROCESS IMPLEMENTATION DETAILS....
PPTX
Control Structures and Looping Basics Understanding Control Flow and Loops Co...
PPTX
clustering type :hierarchical clustering.pptx
PPTX
Computer engineering for collage studen. pptx
PPTX
Lead-acid battery.pptx.........................
PDF
Advancements in Telecommunication for Disaster Management (www.kiu.ac.ug)
PDF
@Regenerative braking system of DC motor
PDF
Small Space Big Design - Amar DeXign Scape
PDF
Welcome to ISPR 2026 - 12th International Conference on Image and Signal Pro...
PDF
k-means algorithm with numerical solution.pdf
PPTX
Supercapacitor.pptx...............................
PDF
Grade 11 Quarter 3 Gravitational Potentional Energy
PPTX
2-Photoelectric effect, phenomena and its related concept.pptx
PPTX
TRANSPORTATION ENGINEERING Unit-5.2.pptx
Generative AI Deep Dive: Architectures, Mechanics, and Future Applications
PRIZ Academy - Thinking The Skill Everyone Forgot
CEC369 IoT P CEC369 IoT P CEC369 IoT PCEC369 IoT PCEC369 IoT P
Washing-Machine-Simulation-using-PICSimLab.pptx
K-nearest neighbouring machine learing algorithm .pptx
Blockchain and cryptography Lecture Notes
31.03.24 - 7.CURRICULUM & TEACHING - LEARNING PROCESS IMPLEMENTATION DETAILS....
Control Structures and Looping Basics Understanding Control Flow and Loops Co...
clustering type :hierarchical clustering.pptx
Computer engineering for collage studen. pptx
Lead-acid battery.pptx.........................
Advancements in Telecommunication for Disaster Management (www.kiu.ac.ug)
@Regenerative braking system of DC motor
Small Space Big Design - Amar DeXign Scape
Welcome to ISPR 2026 - 12th International Conference on Image and Signal Pro...
k-means algorithm with numerical solution.pdf
Supercapacitor.pptx...............................
Grade 11 Quarter 3 Gravitational Potentional Energy
2-Photoelectric effect, phenomena and its related concept.pptx
TRANSPORTATION ENGINEERING Unit-5.2.pptx

Scala Programming for Semantic Web Developers ESWC Semdev2015

  • 1.
    Scalable and ReactiveProgrammingfor SemanticWeb DevelopersJean-Paul CalbimonteLSIR EPFLDevelopers Workshop. Extended Semantic Web Conference ESWC 2015Portoroz, 31.05.2015@jpcik
  • 2.
    Semantic Web Devs2HavefunLove challengesNeed cool toolsSesame
  • 3.
    Scala: Functions andObjects3JVM languageBoth object and functional orientedEasy Java-interopReuse Java librariesGrowing community
  • 4.
    RDF in Jena:in ScalaString personURI = "http://somewhere/JohnSmith";Model model = ModelFactory.createDefaultModel();model.createResource(personURI).addProperty(VCARD.FN,"John Smith");Type inferenceNot too useful; and ()4Terser & compact codeType-safe DSLCompiler takes careval personURI = "http://somewhere/JohnSmith"val model = ModelFactory.createDefaultModelmodel.createResource(personURI).addProperty(VCARD.FN,"John Smith")sw:JohnSmith “John Smith”vcard:FNval personURI = "http://somewhere/JohnSmith"implicit val model = createDefaultModeladd(personURI,VCARD.FN->"John Smith")boilerplateString convertedto Resource
  • 5.
    Some more RDF5StringpersonURI = "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 = createDefaultModeladd(personURI,VCARD.FN->fullName,VCARD.N ->add(bnode,VCARD.Given -> givenName,VCARD.Family->familyName))sw:JohnSmith“John Smith”vcard:FN_:n“John”“Smith”vcard:Nvcard:Givenvcard:FamilyBlank nodeScala DSLs customizablePredicate-objects are pairs
  • 6.
    Some more RDFin Jena6implicit val m=createDefaultModelval 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 RDFYou can do it even nicer
  • 7.
    Exploring an RDFGraph7ArrayList<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.toStringcase l:Literal=>l.getString}Imperative iteration of collectionsType-based conditional executionType castingCase typeMap applied to operators
  • 8.
  • 9.
    Query with SPARQL9valqueryStr = """select distinct ?Conceptwhere {[] 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 endpointSimplified access toQuery solutionsFutures: asnyc executionNon blocking codeFallback alternative execution
  • 10.
    Actor Model10Actor1Actor2mNo sharedmutable stateAvoid blocking operatorsLightweight objectsLoose couplingcommunicatethrough messagesmailboxstatebehaviornon-blocking responsesend: fire-forgetImplementations: e.g. Akka for Java/ScalaParentActor1SupervisionhierarchySupervisionActor2Actor4XActor2Actor1Actor2mActor3Actor4mmRemoting
  • 11.
    Reactive SystemsEvent-DrivenJonas Boner.Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems. 2013.Events:reacttoScalableLoad:ResilientFailure:ResponsiveUsers:11
  • 12.
    RDF Streams: Actors12valsys=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 consumerActor receive methodImplements behaviorMessage-passing modelRDF producerAsync message passing
  • 13.
    Web RDF Services13GET/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 StringWriterval statements=m.listStatements(iri(prefix+id+"/"),null,null)val model=createDefaultModelstatements.foreach(i=>model.add(i))model.write(sw, "TURTLE")Future(Ok(sw.toString).as("text/turtle").withHeaders(ETAG->tag,ALLOW->"GET,POST"))}Routing rulesController returns RDF async
  • 14.
    OWLAPI: reasoning14val onto=mgr.createOntologyvalartist=clazz(pref+"Artist")val singer=clazz(pref +"Singer")onto += singer subClassOf artistval reasoner = new RELReasonerFactory.createReasoner(onto)val elvis=ind(pref+"Elvis")reasoner += elvis ofClass singerreasoner.reclassifyreasoner.getIndividuals(artist) foreach{a=>println(a.getRepresentativeElement.getIRI)}Creating OWL classesDeclaring class relationshipsDeclare instances
  • 15.
    How is itdone?15object 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) } }
  • 16.

[8]ページ先頭

©2009-2025 Movatter.jp