Skip to content

Commit

Permalink
Added extract mode into the Whiteboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferada committed Sep 6, 2011
1 parent 2d3dd3d commit 3efc0bf
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 7 deletions.
13 changes: 13 additions & 0 deletions mate.n3
Expand Up @@ -8,16 +8,19 @@

:AvailabilityResult
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
rdfs:label "Verfügbarkeitsresultat"@de , "Availability Result"@en ;
:primaryKey :AvailabilityKey .

:Person
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
rdfs:label "Person" ;
owl:equivalentClass foaf:Person .

:AvailabilityResultMod
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
rdfs:label "Availability Result (modified)"@en , "Verfügbarkeitsresultat (modifiziert)"@de ;
:primaryKey :AvailabilityModKey .

Expand All @@ -39,6 +42,11 @@
for example to merge new sensor values into the database and
create histories on them."""@en .

:ignoreIndex
a owl:AnnotationProperty ;
rdfs:domain owl:Class ;
rdfs:range xsd:boolean .

:AvailabilityKey
a :PropertyList ;
rdf:first :jid ;
Expand All @@ -55,6 +63,7 @@

:HistoryEntry
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
rdfs:label "History Entry"@en , "History-Eintrag"@de .

:available
Expand All @@ -68,6 +77,7 @@

:PropertyList
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
rdfs:label "Property List"@en , "Property-Liste"@de ;
rdfs:subClassOf rdf:List ;
rdfs:subClassOf
Expand All @@ -90,6 +100,7 @@

:ExtractMode
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
rdfs:label "Extract Mode"@en , "Extraktionsmodus"@de ;
owl:oneOf (:closure :1-step :explicit) .

Expand Down Expand Up @@ -128,6 +139,7 @@

:Activity
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
rdfs:label "Activity"@en , "Aktivität"@de ;
owl:oneOf (:shortBreak :longBreak :reading :writing :meeting) .

Expand All @@ -144,6 +156,7 @@

:Interruptibility
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
owl:oneOf (:uninterruptible :interruptible :maybeInterruptible) ;
rdfs:label "Interruptibility"@en , "Unterbrechbarkeit"@de .

Expand Down
5 changes: 5 additions & 0 deletions sensors.n3
Expand Up @@ -13,6 +13,7 @@

:DoorSensorState
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
rdfs:label "Türsensorzustand"@de , "Door Sensor State"@en ;
owl:oneOf (:uninterruptible :interruptible :maybeInterruptible) .

Expand Down Expand Up @@ -80,6 +81,7 @@

:SensorValue
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
# sensor values have exactly one associated sensor
rdfs:subClassOf
[ a owl:Restriction ;
Expand Down Expand Up @@ -131,15 +133,18 @@

:DesktopSensorFrequency
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
rdfs:label "Desktop Sensor Frequency"@en , "Desktopsensorfrequenz"@de ;
owl:oneOf (:inactive :active :veryActive) .

:DesktopSensorProgram
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
rdfs:label "Desktopsensorprogramm"@de , "Desktop Sensor Program"@en ;
owl:oneOf (:unknown :text :browser) .

:CubeSensorState
a owl:Class ;
:ignoreIndex "true"^^xsd:boolean ;
rdfs:label "Cube-Sensorzustand"@de , "Cube Sensor State"@en ;
owl:oneOf (:shortBreak :longBreak :reading :writing :meeting) .
77 changes: 71 additions & 6 deletions src/board/MateClass.java
Expand Up @@ -20,31 +20,96 @@ public class MateClass {

public List<Property> primaryKey;

public enum ExtractMode {
EXPLICIT,
ONE_STEP,
CLOSURE
};

public ExtractMode mode;

public List<Property> extractExplicit;

/**
* Creates a new MateClass instance if possible (i.e. the class of
* that name exists and its primary key is defined).
*/
public static MateClass create (OntClass typeClass) {
Statement statement = typeClass.getProperty (Mate.primaryKey);
Statement statement = typeClass.getProperty (Mate.ignoreIndex);

try {
if (statement != null && statement.getBoolean ())
return null;
}
catch (Exception e) {
logger.error ("value for property ignoreIndex wasn't a boolean: "
+ statement.getObject () + ", ignoring class "
+ typeClass.getLocalName ());
return null;
}

statement = typeClass.getProperty (Mate.primaryKey);
if (statement == null) {
logger.warn ("there is no primary key defined for type " + typeClass.getLocalName () + ", can't create class");
return null;
}

List<Resource> resources = Whiteboard.convertRdfList (statement.getResource ());
List<Property> properties = new ArrayList<Property> ();
List<Property> key = new ArrayList<Property> ();

for (Resource resource : resources) {
logger.trace ("resource = " + resource.getURI ());
properties.add (ResourceFactory.createProperty (resource.getURI ()));
logger.trace ("resource = " + resource.getLocalName ());
key.add (ResourceFactory.createProperty (resource.getURI ()));
}

ExtractMode mode = ExtractMode.ONE_STEP;
List<Property> extract = null;

statement = typeClass.getProperty (Mate.extractMode);
if (statement == null)
logger.info ("there is no extract mode defined for type " + typeClass.getLocalName () + ", defaulting to " + mode);
else {
Resource resource = statement.getResource ();

if (resource.equals (Mate.explicit))
mode = ExtractMode.EXPLICIT;
else if (resource.equals (Mate.oneStep))
mode = ExtractMode.ONE_STEP;
else if (resource.equals (Mate.closure))
mode = ExtractMode.CLOSURE;
else
logger.error ("unknown extract mode " + resource.getLocalName () + ", defaulting to " + mode);
}

if (mode == ExtractMode.EXPLICIT) {
statement = typeClass.getProperty (Mate.extractExplicit);

if (statement == null) {
logger.error ("extract mode is explicit, but no list of properties is defined, ignoring class "
+ typeClass.getLocalName ());
return null;
}

resources = Whiteboard.convertRdfList (statement.getResource ());
extract = new ArrayList<Property> ();

for (Resource resource : resources) {
logger.trace ("extract = " + resource.getLocalName ());
extract.add (ResourceFactory.createProperty (resource.getURI ()));
}

if (!extract.containsAll (key))
logger.warn ("extract list doesn't contain all defined primary key properties");
}

return new MateClass (typeClass, properties);
return new MateClass (typeClass, key, mode, extract);
}

private MateClass (OntClass base, List<Property> primaryKey) {
private MateClass (OntClass base, List<Property> primaryKey, ExtractMode mode, List<Property> extract) {
this.base = base;
this.primaryKey = primaryKey;
this.mode = mode;
extractExplicit = extract;
}

public String toString () {
Expand Down
18 changes: 17 additions & 1 deletion src/board/Whiteboard.java
Expand Up @@ -489,6 +489,22 @@ private void addPrimaryKeyChecks (Var var, Resource marker, MateClass klass, Ele
addFilters (var, marker, klass, group);
}

public Model extract (Resource marker, MateClass klass) {
switch (klass.mode) {
case EXPLICIT:
Model result = ModelFactory.createDefaultModel ();
for (Property property : klass.extractExplicit)
result.add (marker.listProperties (property));
return null;
case ONE_STEP:
return ModelFactory.createDefaultModel ().add (marker.listProperties ());
case CLOSURE:
return Closure.closure (marker, true);
default:
throw new IllegalArgumentException ("well, this can't happen, ExtractMode should only have three possible values");
}
}

public List<Model> matching (Model test, Resource marker, MateClass klass) {
List<Model> result = new ArrayList<Model> ();

Expand Down Expand Up @@ -519,7 +535,7 @@ public List<Model> matching (Model test, Resource marker, MateClass klass) {
ResultSet results = exec.execSelect ();
while (results.hasNext ()) {
QuerySolution solution = results.next ();
result.add (Closure.closure (solution.get ("marker").asResource (), true));
result.add (extract (solution.get ("marker").asResource (), klass));
}
}
finally {
Expand Down
10 changes: 10 additions & 0 deletions src/board/vocabulary/Mate.java
Expand Up @@ -16,8 +16,18 @@ public final class Mate {

public static final Resource HistoryEntry = resource ("HistoryEntry");

public static final Property ignoreIndex = property ("ignoreIndex");

public static final Property primaryKey = property ("primaryKey");

public static final Property extractMode = property ("extractMode");

public static final Resource explicit = property ("explicit");
public static final Resource oneStep = property ("1-step");
public static final Resource closure = property ("closure");

public static final Property extractExplicit = property ("extractExplicit");

public static final Property historyType = property ("historyType");

public static final Property historyEntries = property ("historyEntries");
Expand Down

0 comments on commit 3efc0bf

Please sign in to comment.