KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager...

Post on 16-Jul-2020

1 views 0 download

Transcript of KOMMA - EclipseCon 2020 · KOMMA modules KOMMA – RDF mapper and editing framework Entity manager...

© Fraunhofer IWU

KOMMAModeling with RDF and Linked Data

Ken Wenzelken.wenzel@iwu.fraunhofer.de

© Fraunhofer IWU

World Wide Web (1991)

Linked Documents

Document Documenthref

Document

href href

Document

href

WW

W (

1991

)

© 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

© 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

© 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

© 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

© 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}

© 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

© 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)

© Fraunhofer IWU

Example: Simple smart home application

Source: FreeImages.com

Source: FreeImages.com

© Fraunhofer IWU

Example: Simple smart home application

© Fraunhofer IWU

Data model

controls

House

Floor

Room

Switch Lampon:boolean on:boolean

Model

controls

© 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

© Fraunhofer IWU

Vocabulary (Meta-models)

Source: Designed by Freepik

© Fraunhofer IWU

Create ontology file for smart home vocabulary

file, format and URI/URL

© Fraunhofer IWU

Edit ontology directy in Eclipse (OWL editor)

Properties:contains,controls

Classes:House, Floor, Room etc.

Attributes and restrictions:Houses contain only floors

© 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

© Fraunhofer IWU

Turtle file for the OWL ontology (smarthome.ttl)

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

© Fraunhofer IWU

Instantly edit instance data with generic components

List, tree andtable views

“New” actions arepopulated fromontology

“New” actions arepopulated fromontology

Generic iconsand labels

© Fraunhofer IWU

Work with RDF in Java

Object-oriented:● classes● single inheritance● static

Triples:● statements about

objects● multiple types● multiple inheritance● dynamic

© 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

© Fraunhofer IWU

Java interfaces represent RDF types

Without @Iri: ● Implemented by you

Without @Iri: ● Implemented by you

Note: IRI = Internationalized Resource Identifier

© Fraunhofer IWU

Java classes implement behaviour

Compute customlabel from controlsproperty Method chaining:

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

SwitchToggles controlled components

© 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

© 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

© 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

© 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);

© 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

© Fraunhofer IWU

Display and edit data with SWT and JFace

© 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

© 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#>

© Fraunhofer IWU

Register modules, adapters and URI resolution rules as extensions

© Fraunhofer IWU

Final application

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

● 11 Java files● ca. 300 lines of code

© Fraunhofer IWU

Final application

© Fraunhofer IWU

Final application

Switch action

Edit elementstructure

Edit objectproperties

Select elementtype

Custom iconsand labels

Updates onmodel changes

© 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

© Fraunhofer IWU