Towards a second generation Topic Maps engine

27
TMRA 2008: Towards a second generation Topic Maps engine 2008-10-17 1 of 27 Xuân Baldauf <[email protected]>, Robert Amor <[email protected]> Towards a second generation Topic Maps Engine

description

The core of the second generation Topic Maps standards (TMDM, XTM2.0) has been finalized, yet the uptake is still slow. In this paper, we highlight engineering considerations for a novel backend for the TM4J open source topic maps engine, which is currently in development, but already usable for some purposes. As the name suggests, the “TMDM” backend is designed to reflect the TMDM specification closely. In fact, it is much closer to the TMDM than to the internal legacy TM4J data model (which is based on the XTM 1.0 data model). This motivates a bridging layer between the TMDM and the XTM 1.0 data model. We emphasize how merging is implemented in the “TMDM” backend and conclude with some synthetic merging benchmarks of the current “TMDM” backend prototype.

Transcript of Towards a second generation Topic Maps engine

Page 1: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

1 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Towards a second generation Topic Maps Engine

Page 2: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

2 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Overview

technical talk

API design

multiple layers

event handling

merging done slowly or fastly

Page 3: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

3 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Objectives

need a Java TM engine

with TMDM supportsemantically

syntactically (names of methods match TMDM)

with instant merging

with dynamic (reversable) merging

with support for modern Java 1.5 features (generics, etc.)

which can act as backend for TM4J1 applications

with persistence support

Page 4: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

4 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Idea

develop a new backend for TM4J

Page 5: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

5 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

„TMDM“ backend

is layered

is (currently) RAM-only

can do topic merging fast

Page 6: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

6 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Layers

what?

layer ≈ coverage of all TMDM item types under a particular concern

why?

separation of concerns: do one thing, and do it well

modularity of architecture:replace a layer implementationby another layer implementation

Page 7: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

7 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Layers

how?

layer ≈ set of classes and interfaces in one Java package

communication between layers bymethod calls

event listeners (later)

Page 8: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

8 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Layers

which?

one layer for accessing a topic map

one layer for just reading a topic map

one layer for storing a topic map

one layer for merging a topic map

one layer for compatibility with TM4J1

Page 9: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

9 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

TMDM read-write interfaces layerConcern: accessing a topic map

set of interfaces in package org.tm4j.topicmap.tmdm:

TopicMap extends ReifiableTopic extends TopicMapConstructTopicName extends ScopeableVariant extends ScopeableOccurrence extends ScopeableAssociation extends ScopeableAssociationRole extends ReifiableScopeable extends ReifiableScopeReifiable extends TopicMapConstructTopicMapConstruct

Page 10: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

10 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Example: AssociationRolepublic interface AssociationRole extends Reifiable, ReadableAssociationRole { public ReadableTopic getType();

public ReadableTopic getPlayer();

public Association getParent();

public void setType(Topic type);

public void setPlayer(Topic player);}

note: no setter for parent.

Page 11: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

11 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

TMDM read-only interfaces layerConcern: just reading a topic map

set of interfaces in package org.tm4j.topicmap.tmdm:

ReadableTopicMapReadableTopicReadableTopicNameReadableVariantReadableOccurrenceReadableAssociationReadableAssociationRoleReadableScopeableReadableScopeReadableReifiableReadableTopicMapConstruct

Page 12: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

12 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Example: ReadableOccurencepublic interface ReadableOccurrence extends ReadableScopeable { public ReadableTopic getType(); public Locator getDatatype(); public String getValue(); public ReadableTopic getParent();}

Page 13: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

13 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

TMDM Basic implementation layer

Concern: storing a topic map

set of classes in package org.tm4j.topicmap.tmdm.basic:

BasicTopicMapBasicTopicBasicTopicNameBasicVariantBasicOccurrenceBasicAssociationBasicAssociationRoleBasicScopeableBasicScopeBasicReifiableBasicTopicMapConstruct

Page 14: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

14 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Example: BasicAssociationpublic class BasicAssociation extends BasicScopeable implements Association { BasicTopicMap parent; BasicTopic type; Set<BasicAssociationRole> toles;

protected BasicAssociation(BasicTopicMap parent, BasicTopic type,BasicScope scope)

public BasicTopicMap getParent()

public void setType(Topic type) public void setType(BasicTopic type) public BasicTopic getType()

public BasicAssociationRole createRole(Topic type,Topic player) public BasicAssociationRole createRole(BasicTopic type, BasicTopic player) public Set<BasicAssociationRole> getRoles()}

Page 15: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

15 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

TMDM Merged implementation layer

Concern: merging a topic map

set of classes in package org.tm4j.topicmap.tmdm.merged:

MergedTopicMapMergedTopicMergedTopicNameMergedVariantMergedOccurrenceMergedAssociationMergedAssociationRoleMergedScopeableMergedScopeMergedReifiableMergedTopicMapConstructMergedTopicMapView

Page 16: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

16 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

MergedTopicMapConstructpublic abstract class MergedTopicMapConstruct<I extends ReadableTopicMapConstruct> extends TMDMObject implements ReadableTopicMapConstruct { protected List<I> components; protected MergedTopicMapView container;

protected MergedTopicMapConstruct(MergedTopicMapView container) protected MergedTopicMapConstruct(MergedTopicMapView container,I firstComponent)

protected MergedTopicMapView getContainer()

public boolean containsComponent(I component) protected void addComponent(I component) protected void removeComponent(I component) public Collection<I> getComponents() public I getRandomComponent()

public Set<Locator> getItemIdentifiers() protected Collection<Set<Locator>> getItemIdentifiersSetCollection() public Set<Locator> getItemIdentifiersSet() public Collection<Locator> getItemIdentifiersCollection() protected boolean containsItemIdentifier(Locator itemIdentifier)}

Page 17: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

17 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Example: MergedAssociationRolepublic class MergedAssociationRole extends MergedReifiable<ReadableAssociationRole,MergedAssociationRoleKey> implements ReadableAssociationRole {

protected MergedAssociationRole(MergedTopicMapView container, MergedAssociationRoleKey key, ReadableAssociationRole firstComponent) { super(container,key,firstComponent); }

public MergedTopic getType() { return getContainer().getMergedTopic(getRandomComponent().getType()); }

public MergedTopic getPlayer() { return getContainer().getMergedTopic(getRandomComponent().getPlayer()); }

public MergedAssociation getParent() { return getContainer().getMergedAssociation(getRandomComponent().getParent()); }}

Page 18: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

18 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

TM4J1 compatibility layer

Concern: exposing a TMDM layer topic map using the TM4J1 API

set of classes in package org.tm4j.topicmap.tmdm.tm4j1:

TopicMapImplTopicImplBaseNameImplVariantImplOccurrenceImplAssociationImplMemberImplScopedObjectImplTopicMapObjectImpl

Wrap around TMDM to provide TM4J1 (=XTM1) semantics

Page 19: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

19 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

TopicMapObjectImplpublic abstract class TopicMapObjectImpl< I extends org.tm4j.topicmap.tmdm.TopicMapConstruct, V extends org.tm4j.topicmap.tmdm.ReadableTopicMapConstruct> implements org.tm4j.topicmap.TopicMapObject {

protected I representedObject; protected TopicMapImpl container;}

Page 20: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

20 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Event Handling

Basic idea: make event firing just a method call

Thus:

all event parameters are method call parameters

default implementation: empty method

Rationale

keep it small and simple

(let the JVM) optimize away unnecessary method calls

Page 21: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

21 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

TopicMapEventListenerpublic interface TopicMapEventListener<TM extends ReadableTopicMap, T extends ReadableTopic, A extends ReadableAssociation, O extends ReadableOccurrence, TMC extends ReadableTopicMapConstruct, TN extends ReadableTopicName, V extends ReadableVariant, AR extends ReadableAssociationRole> { public void notifyTopicCreated(TM topicMap,T topic); public void notifyTopicRemoved(TM topicMap,T topic);

public void notifySubjectIdentifierAdded (TM topicMap,T topic,Locator sid); public void notifySubjectIdentifierRemoved(TM topicMap,T topic,Locator sid); public void notifySubjectLocatorAdded (TM topicMap,T topic,Locator sid); public void notifySubjectLocatorRemoved (TM topicMap,T topic,Locator sid);

public void notifyItemIdentifierAdded (TM topicMap,TMC topicMapConstruct, Locator itemIdentifier) throws DuplicateItemIdentifierException; public void notifyItemIdentifierRemoved (TM topicMap,TMC topicMapConstruct, Locator itemIdentifier);}

Page 22: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

22 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Peculiarities

Scope is a first-class class

replace the set of all themes by a pointer

# of distinct scopes is small, thus

# of distinct Scope objects is small

Page 23: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

23 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Bigger pictureTM4J1 compatibility layer

Basic layer

Merged layer

TopicMapEventListener

TopicImpl

BasicTopic

MergedTopic

representedObject

TopicMapImpl

BasicTopicMap

MergedTopicMap

representedObject

components

container container

MergedTopicMapView

components

eventListener

topicToMergedTopic

parentparent

BasicTopic

containercontainer

TopicImpl

mergedTopicMap

Page 24: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

24 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Merging

„A merge B = C“ is slow O(n²)

„A merge B = B“ is fast O(n·log(n))

if A is smaller than B

Page 25: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

25 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Merging Benchmark

0 40000 80000 120000

0

100

200

300

400

500

600

700

800

900

21,51

458,97

825,49

processing time

# TopicMapConstructs

proc

essi

ng t

ime

in s

econ

ds “memory” backend“TMDM” backend (no merging optimization)“TMDM” backend (with merging optimization)

Page 26: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

26 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

What to do?

instantaneous unmerging

computationally expensive

Should we support it? What to do if not?

implement some methods

autogenerate engine (Domain Specific Languages)

late merging vs. early merging

Page 27: Towards a second generation Topic Maps engine

TMRA 2008: Towards a second generation Topic Maps engine2008-10-17

27 of 27Xuân Baldauf <[email protected]>, Robert Amor <[email protected]>

Thank you

Questions?