package com.franz.ag.examples;
import com.franz.ag.*;
public class AGTemporalIntervalIntervalRelations {
/**
* Demonstrates temporal queries involving Allen relations between intervals.
*
* @param unused
* @throws AllegroGraphException
*/
public static void main(String[] args) throws AllegroGraphException {
// Connect to server, which must already be running.
AllegroGraphConnection ags = new AllegroGraphConnection();
try {
ags.enable();
} catch (Exception e) {
throw new AllegroGraphException("Server connection problem", e);
}
// Create a fresh triple store for this example.
AllegroGraph ts = ags.renew("temporal", AGPaths.TRIPLE_STORES);
// Add a datatype mapping so that XMLSchema#dateTime typed literals are
// loaded as date-time UPI's, enabling more efficient storage and range
// querying over dates.
String[] map = new String[3];
map[0] = "http://www.w3.org/2000/01/XMLSchema#dateTime";
map[1] = "date-time";
map[2] = "datatype";
ts.addDataMapping(map);
// Load some temporal data
AGUtils.loadNTriplesWithTiming(ts, AGPaths.dataSources("temporal.nt"));
// Index the store for faster querying
AGUtils.indexAllTriplesWithTiming(ts);
// Register any namespaces
ts.registerNamespace("ex", "http://example.org/");
ts.registerNamespace("t", "http://franz.com/ns/allegrograph/3.0/temporal/");
Cursor cc = ts.getStatements(null, null, null);
AGUtils.showTriples(cc);
// Query the store for intervals satisfying interval-before
String pquery = "(?i)"
+ "(interval-before ?i !ex:i68)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-meets
pquery = "(?i)"
+ "(interval-meets ?i !ex:i68)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-overlaps
pquery = "(?i)"
+ "(interval-overlaps ?i !ex:i38)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-starts
pquery = "(?i)"
+ "(interval-starts ?i !ex:i16)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-during
pquery = "(?i)"
+ "(interval-during ?i !ex:i27)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-finishes
pquery = "(?i)"
+ "(interval-finishes ?i !ex:i38)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-cotemporal
pquery = "(?i)"
+ "(interval-cotemporal ?i !ex:i36)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-after
pquery = "(?i)"
+ "(interval-after ?i !ex:i45)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-met-by
pquery = "(?i)"
+ "(interval-met-by ?i !ex:i14)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-overlapped-by
pquery = "(?i)"
+ "(interval-overlapped-by ?i !ex:i36)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-started-by
pquery = "(?i)"
+ "(interval-started-by ?i !ex:i14)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-contains
pquery = "(?i)"
+ "(interval-contains ?i !ex:i36)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Query the store for intervals satisfying interval-finished-by
pquery = "(?i)"
+ "(interval-finished-by ?i !ex:i48)";
AGUtils.doPrologSelectDistinct(ts, pquery);
// Close the triple store and disconnect from the server.
ts.closeTripleStore();
ags.disable();
}
}