|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.ceryle.tm.assertion.AssertionQueryExecutor
public class AssertionQueryExecutor
A utility class used to handle assertion queries from a Topic Map.
An assertion is a Topic Map Association typed as an Assertion,
not to be confused with Assertion
(which can be created by conversion from an Association). Assertions
are simple logical sentences of the form:
Subject Predicate Object
whose predicates (i.e., type and roles) are defined by an Association
template.
A query takes the same form as the above triple, locating the Set of assertions using one of three logical operators:
This class began using native TM4J methods and is currently being converted over to TMAPI. The one issue is that the current Inference implementation is TM4J-based, so either a wrapper or alternative class needs to be written. Or: we need to dump TMAPI (gasp!).
Whereas the subject, predicate and object are part of the TopicMap Association (being the Association type and role Topics), the wiki page name could be connected to the Association in a number of different ways, such as: reifying the Association as a Topic and attaching it as a typed property, linking to the Association's ID from the wiki page Topic, etc. The simplest approach is to scope the Association by the page(s) that declared it and then query to see if a given page appears in that Association's scope. Since this is appropriate according to the model there's no real problem but it is a bit backhanded.
Once the substitution has been made, the TopicMap can then provide
the set of over a dozen "inferencing" methods, as supplied by the
Inferencer API (and, of course,
InferencerImpl implementation).
All inferencing is done over TopicMap objects, not wiki page names,
but there should be a Topic for every wiki page, with conversion
between via getTopicByName(String) and
getPageForTopic(Topic).
for the constants used as
parameters in Assertion queries.,
Assertion,
WikiMapManager| Field Summary | |
|---|---|
protected boolean |
USE_REGEX
Use regular expression (regex) matching on Assertion parameters? |
| Constructor Summary | |
|---|---|
AssertionQueryExecutor(TopicMapProcessor tmproc,
TopicMap topicmap,
TopicNameIndex index)
Constructor for a AssertionQueryExecutor. |
|
| Method Summary | |
|---|---|
Collection |
getAssertion(String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode)
Returns an assertion (an Association of type 'Assertion') having the wiki page name, predicate and terms. |
int |
getAssertionCount()
Return the assertion count. |
Collection |
getAssertions()
Returns the Collection of all Associations in the TopicMap having a Scope indicating that they are based on Assertions. |
Collection |
getAssertions(Collection associations,
int templateMode)
A filter that returns a Collection containing all the assertions (notably, Topic Map Associations, not Assertion objects) in the provided collection, or if null, the entire registry. |
Collection |
getAssertions(Collection associations,
String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode)
Returns the Collection of all Associations matching Assertions (that is, Associations typed as Assertions) having subject (assertion[0]), predicate (assertion[1]), and/or object (assertion[2]) as Strings. |
Collection |
getAssertionTemplates()
Returns a Collection containing all the Assertion templates in the registry. |
String |
getLabelForPage(String pagename)
A convenience method that returns a Topic-based label for the given page (referenced by name), returning the original pagename if the Topic does not provide an alternative. |
String |
getPageForTopic(Topic topic)
A convenience method that "converts" the Topic topic to its wiki page name (returning its label). |
Collection |
getPredicatesOfType(Collection associations,
Topic predicate)
Returns a Set view of all the Associations in the TopicMap tm having a Scope indicating that they are based on assertions. |
Set |
getSubclasses(String pagename)
Returns a Set containing the subclasses of the Topic backing wiki page pagename. |
Set |
getSuperclasses(String pagename)
Returns a Set containing the superclasses of the Topic backing wiki page pagename. |
Topic |
getTopicByName(String label)
Returns a Topic with a base name in the XTM 'Display' scope of label, throwing a TopicMapException if provided with a null parameter or is unable to locate and/or create the Topic. |
TopicMap |
getTopicMap()
Returns the TopicMap as a TM4J TopicMap. |
TopicMapProcessor |
getTopicMapProcessor()
Return the TopicMapProcessor used by this AQE. |
boolean |
hasAssertion(String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode)
Returns true if an Assertion equivalent to one created with the provided subject, predicate, and object is contained in the registry. |
protected Collection |
queryAssertions(Collection associations,
String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode,
boolean returnFirst)
Perform a query based on the parameters. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected boolean USE_REGEX
| Constructor Detail |
|---|
public AssertionQueryExecutor(TopicMapProcessor tmproc,
TopicMap topicmap,
TopicNameIndex index)
throws TopicMapException
tmproc - the parent TopicMapProcessor.topicmap - the TopicMap to be queried.index - the index of Topic names.
TopicMapException| Method Detail |
|---|
public TopicMapProcessor getTopicMapProcessor()
public TopicMap getTopicMap()
public int getAssertionCount()
public Collection getAssertions()
public Collection getAssertionTemplates()
public Collection getAssertions(Collection associations,
int templateMode)
associations - the base collection to query, or if null, the entire registry.templateMode - assertions or templates or both, as
AssertionQuery.TEMPLATES_EXCLUDE,
AssertionQuery.TEMPLATES_ONLY, or
AssertionQuery.TEMPLATES_INCLUDE.
public Collection getAssertions(Collection associations,
String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode)
throws AssertionQueryException
The logicMode determines the logic used for the query.
Null values are ignored; the String array must either be null or contain exactly three elements (any or all of which can be null).
associations - the beginning Collection to query; if null, the entire TopicMap is queriedpagename - the name of the wiki page where the assertion was madesubject - the WikiName identifier for the subject of the querypredicate - the WikiName identifier for the predicate of the queryobject - the WikiName identifier for the object of the querytemplateMode - assertions or templates or both, as
AssertionQuery.TEMPLATES_EXCLUDE,
AssertionQuery.TEMPLATES_ONLY, or
AssertionQuery.TEMPLATES_INCLUDE.logicMode - the logical query mode, as either
AssertionQuery.LOGICAL_ALL,
AssertionQuery.LOGICAL_AND, or
AssertionQuery.LOGICAL_OR.
AssertionQueryException
public boolean hasAssertion(String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode)
throws AssertionQueryException
pagename - the wiki page source of the Assertionsubject - the wiki page name of the Assertion's subjectpredicate - the wiki page name of the Assertion's predicateobject - the wiki page name of the Assertion's objecttemplateMode - assertions or templates or both, as
AssertionQuery.TEMPLATES_EXCLUDE,
AssertionQuery.TEMPLATES_ONLY, or
AssertionQuery.TEMPLATES_INCLUDE.logicMode - the logical query mode, as either
AssertionQuery.LOGICAL_ALL,
AssertionQuery.LOGICAL_AND, or
AssertionQuery.LOGICAL_OR.
AssertionQueryException
public Collection getAssertion(String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode)
throws AssertionQueryException
Even though this method only returns at most one object, we return a Collection so that both query methods use the same return type (well, except hasAssertion() with its boolean).
AssertionQueryException
protected Collection queryAssertions(Collection associations,
String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode,
boolean returnFirst)
throws AssertionQueryException
If the value for pagename is AssertionQuery.PAGENAME_ANY
the query will match on any page name value.
associations - the beginning collection of Associations to query; if null the entire Topic Mappagename - the wiki page name of the querysubject - the subject of the querypredicate - the predicate of the queryobject - the object of the querytemplateMode - assertions or templates or both, as
AssertionQuery.TEMPLATES_EXCLUDE,
AssertionQuery.TEMPLATES_ONLY, or
AssertionQuery.TEMPLATES_INCLUDE.logicMode - the logical query mode, as either
AssertionQuery.LOGICAL_ALL,
AssertionQuery.LOGICAL_AND, or
AssertionQuery.LOGICAL_OR.returnFirst - if true return upon first hit
AssertionQueryException
public Topic getTopicByName(String label)
throws TopicMapException
label - the label of the returned Topic
TopicMapException - if unable to locate and/or create the Topic
IllegalStateException - if this method is called prior to creation of the TopicMappublic String getLabelForPage(String pagename)
IllegalStateException - if this method is called prior to creation of the TopicMappublic String getPageForTopic(Topic topic)
IllegalStateException - if this method is called prior to creation of the TopicMap
public Collection getPredicatesOfType(Collection associations,
Topic predicate)
IllegalStateException - if this method is called prior to creation of the TopicMap
public Set getSubclasses(String pagename)
throws TopicMapException
TopicMapException
public Set getSuperclasses(String pagename)
throws TopicMapException
TopicMapException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||