komma - eclipsecon 2020 · komma modules komma – rdf mapper and editing framework entity manager...

37
© Fraunhofer IWU KOMMA Modeling with RDF and Linked Data Ken Wenzel [email protected]

Upload: others

Post on 16-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

KOMMAModeling with RDF and Linked Data

Ken [email protected]

Page 2: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

World Wide Web (1991)

Linked Documents

Document Documenthref

Document

href href

Document

href

WW

W (

1991

)

Page 3: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Semantic Web (2001)

Document Documenthref

Document

href href

Document

href

WW

W (

1991

)

Person Documentcreated

Document

has vita href

Chemnitz

lives in

Document Vitais aSem

antic

Web Web Pageis a

Linked Documents

Linked things with types and relationships

Page 4: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Semantic Web (2001)

Source: Wikipedia

Document Documenthref

Document

href href

Document

href

WW

W (

1991

)

Person Documentcreated

Document

has vita href

Chemnitz

lives in

Document Vitais aSem

antic

Web Web Pageis a

Semantic Web Stack

Page 5: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Source: Wikipedia

Semantic Web – Problems

misunderstood as “intelligent web”

too much focus on logic and automated reasoning

complex ontologies with (too) many classes and restrictions

Semantic Web Stack

Page 6: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Linked Data (2006)

Tim Berners-Lee (2006):

1) Use URIs to name (identify) things.2) Use HTTP URIs so that these things can be looked up

(interpreted, "dereferenced").3) Provide useful information about what a name identifies

when it's looked up, using open standards such as RDF, SPARQL, etc.

4) Refer to other things using their HTTP URIs when publishing data on the Web.

Source: Wikipedia

Source: bnode.org

Page 7: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

RDFResource Description Framework

Data model

Triple (subject, predicate, object): :Maria foaf:knows Paul .:Maria rdf:type Female .:Female rdf:type owl:Class .:Female rdfs:subClassOf Person .:Maria foaf:age 32 .

URIs for objects and predicates Literals for scalar values: 20.4

Vocabulary

integrated: types (rdf:type), lists (rdf:List, rdf:first, rdf:rest) extendable by ontologies (RDF Schema, OWL)

Queries with SPARQL

select ?friend where { :Maria foaf:knows ?friend }

Updates with SPARQL

insert { :Paul foaf:knows ?friend }where { ?friend foaf:knows :Paul}

Page 8: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

KOMMAmodules

KOMMA – RDF mapper and editing framework

Entitymanager

Data manager

Adapters

Models + ModelSets

Eclipse RDF4J

- Manage data from multiple sources (files, URLs, ...)

- Manage display components and interaction

- Support different RDF frameworks(RDF4J, Jena, …)

- Default RDF framework used by KOMMA- Interface to storage backends- Like JDBC+SQL

- Map between Java classes and RDF resources- Transactions, change tracking, caching- Like JPA

http://komma.enilink.net

Page 9: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

KOMMAmodules

Typical operations on each layer

Entitymanager

Data manager

Adapters

Models + ModelSets

Eclipse RDF4J

getText(), getImage(), createCommand(), ...

Models: load(), save(), addImport(), getManager(), …Model sets: createModel(), getModel(), ...

Entity manager: create(), remove(), find(), createQuery(), ...

add(), remove(), match(), createQuery(), …(triple oriented)

Page 10: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Example: Simple smart home application

Source: FreeImages.com

Source: FreeImages.com

Page 11: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Example: Simple smart home application

Page 12: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Data model

controls

House

Floor

Room

Switch Lampon:boolean on:boolean

Model

controls

Page 13: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Features

controls

House

Floor

Room

Switch Lampon:boolean on:boolean

Model

controls

Edit structure

Drag and drop

Undo/Redo

Labels + Icons

Custom actions

Features

Page 14: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Vocabulary (Meta-models)

Source: Designed by Freepik

Page 15: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Create ontology file for smart home vocabulary

file, format and URI/URL

Page 16: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Edit ontology directy in Eclipse (OWL editor)

Properties:contains,controls

Classes:House, Floor, Room etc.

Attributes and restrictions:Houses contain only floors

Page 17: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Reuse vocabulary with imports (owl:imports)

Import KOMMA vocabulary with predefined properties Link to komma:child and komma:containsto trigger default visualisation and editing

Page 18: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Turtle file for the OWL ontology (smarthome.ttl)

Turtle files are plain text files that can be modified with any text editor.

Page 19: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Instantly edit instance data with generic components

List, tree andtable views

“New” actions arepopulated fromontology

“New” actions arepopulated fromontology

Generic iconsand labels

Page 20: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Work with RDF in Java

Object-oriented:● classes● single inheritance● static

Triples:● statements about

objects● multiple types● multiple inheritance● dynamic

Page 21: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Java interfaces represent RDF types

With @Iri: ● Mapped to RDF properties● Implemented by KOMMA● Literals are mapped to Java types

With @Iri: ● Mapped to RDF properties● Implemented by KOMMA● Literals are mapped to Java types

Note: IRI = Internationalized Resource Identifier

Page 22: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Java interfaces represent RDF types

Without @Iri: ● Implemented by you

Without @Iri: ● Implemented by you

Note: IRI = Internationalized Resource Identifier

Page 23: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Java classes implement behaviour

Compute customlabel from controlsproperty Method chaining:

Change value of mapped “on” property andswitch “controlled” components

SwitchToggles controlled components

Page 24: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Use SPARQL for complex queries and updates

Find all switches in any room on the

same floor

FloorSwitchIntelligent floor switch

Compute label

Switch components

Page 25: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Use SPARQL for complex queries and updates

Find all switches in any room on the

same floor

FloorSwitchIntelligent floor switch

Compute label

Switch components

Page 26: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Use SPARQL for complex queries and updates

select ?target where {?floor a sh:Floor; sh:contains+ ?this; sh:contains ?target .?target a [rdfs:subClassOf* sh:Switch] filter not exists { ?target a sh:FloorSwitch }

}

Retrieveswitches

select (count(distinct ?target) as ?count) where {?floor a sh:Floor; sh:contains+ ?this; sh:contains ?target .?target a [rdfs:subClassOf* sh:Switch] filter not exists { ?target a sh:FloorSwitch }

}

Countswitches

Page 27: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

KOMMA modules package interfaces and behaviours

1) Register via plugin.xml

2) Use it programmatically:

IEntityManager em =Guice.createInjector(

new MyEntityManagerModule(new SmartHomeModule()

)).getInstance(IEntityManagerFactory.class).get();

em.create(Lamp.class).on(true);

Page 28: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Object composition at runtime (simplified)

URI

Retrieve rdf:typestatements

Match interfaces and classes according

to @Iri annotations

Create bean class withone field per interface and

behaviour

Bean class for rdf:type smarthome:Switch

1

2

3

<URI> a ?typesmarthome:Switchsmarthome:Switchableowl:Thing

SwitchSwitchSupport

Page 29: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Display and edit data with SWT and JFace

Page 30: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Adapters control presentation and interaction

1) Compute icons, labels, colors, …

2) Provide children for tree structures

3) React on changes of underlying data

4) Control editing actions (add, remove, DnD, …)

5) Support search in tree-like structures

Page 31: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Adapter factories create adapters for RDF resources

Use label() method for instances of type SwitchUse label() method for instances of type Switch

Presentation of classes and properties fromthis adapter's namespace can also be modifiedPresentation of classes and properties fromthis adapter's namespace can also be modified

Specify this adapter factory's namespace:<http://komma.github.io/komma-examples/vocab/smarthome.ttl#>

Specify this adapter factory's namespace:<http://komma.github.io/komma-examples/vocab/smarthome.ttl#>

Page 32: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Register modules, adapters and URI resolution rules as extensions

Page 33: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Final application

https://github.com/komma/komma-examples

● 11 Java files● ca. 300 lines of code

Page 34: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Final application

Page 35: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Final application

Switch action

Edit elementstructure

Edit objectproperties

Select elementtype

Custom iconsand labels

Updates onmodel changes

Page 36: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU

Conclusion

RDF/OWL editor for Eclipse

Object-triple mapping with object composition (multiple types and behaviours per object)

Use SPARQL everywhere to query and update the domain models

Editing framework for RDF data (like EMF.Edit)

Based on Eclipse RDF4J

Works with AND without OSGi

https://github.com/komma/kommahttp://komma.enilink.net

Page 37: KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager Data manager Adapters Models + ModelSets Eclipse RDF4J-Manage data from multiple

© Fraunhofer IWU