Towards a second generation Topic Maps engine

Post on 08-May-2015

1315 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

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

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

1 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

Towards a second generation Topic Maps Engine

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

2 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

Overview

technical talk

API design

multiple layers

event handling

merging done slowly or fastly

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

3 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

4 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

Idea

develop a new backend for TM4J

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

5 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

„TMDM“ backend

is layered

is (currently) RAM-only

can do topic merging fast

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

6 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

7 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

Layers

how?

layer ≈ set of classes and interfaces in one Java package

communication between layers bymethod calls

event listeners (later)

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

8 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

9 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

10 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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.

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

11 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

ReadableTopicMapReadableTopicReadableTopicNameReadableVariantReadableOccurrenceReadableAssociationReadableAssociationRoleReadableScopeableReadableScopeReadableReifiableReadableTopicMapConstruct

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

12 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

13 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

TMDM Basic implementation layer

Concern: storing a topic map

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

BasicTopicMapBasicTopicBasicTopicNameBasicVariantBasicOccurrenceBasicAssociationBasicAssociationRoleBasicScopeableBasicScopeBasicReifiableBasicTopicMapConstruct

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

14 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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()}

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

15 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

TMDM Merged implementation layer

Concern: merging a topic map

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

MergedTopicMapMergedTopicMergedTopicNameMergedVariantMergedOccurrenceMergedAssociationMergedAssociationRoleMergedScopeableMergedScopeMergedReifiableMergedTopicMapConstructMergedTopicMapView

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

16 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

17 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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()); }}

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

18 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

19 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

20 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

21 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

22 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

23 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

24 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

25 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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)

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

26 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

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

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

27 of 27Xuân Baldauf <xuan--tm4j2--2008--tmra.de@baldauf.org>, Robert Amor <trebor@cs.auckland.ac.nz>

Thank you

Questions?

top related