edu.byu.deg.ontos.heuristic
Class NestedGroupHeuristic

java.lang.Object
  extended byedu.byu.deg.ontos.MappingHeuristic
      extended byedu.byu.deg.ontos.heuristic.NestedGroupHeuristic

public class NestedGroupHeuristic
extends MappingHeuristic

A mapping heuristic that generates a relationship based on a relationship set connection that qualifies as a nested group in the traversal of the ontology structure.


Field Summary
protected  ContextualHeuristic ch
           
 
Fields inherited from class edu.byu.deg.ontos.MappingHeuristic
ACCEPTED_MATCH, connComparer, ontIndex, PROPOSED_MATCH, REJECTED_MATCH
 
Constructor Summary
NestedGroupHeuristic()
          Creates a new instance of NestedGroupHeuristic
NestedGroupHeuristic(ExtractionOntologyIndex idx)
          Creates a new instance of NestedGroupHeuristic and initializes it with an indexed ontology.
 
Method Summary
protected  int compareRelSets(edu.byu.deg.osmx.OSMXRelSetConnectionType r1, edu.byu.deg.osmx.OSMXRelSetConnectionType r2, MatchingContext ctxt)
          Defines a total order on a set of relationship set connections by determining, for a pair of such connections, which should precede the other in a sorted list.
protected  MatchingContext findBestSubContext(edu.byu.deg.osmx.OSMXRelSetConnectionType conn, MatchingContext ctxt)
          Determines the likely outer boundaries of the nested group from the given context and returns the result as a matching context.
protected  edu.byu.deg.osmx.OSMXRelSetConnectionType findOuterMaxMany(List maxMany, MatchingContext ctxt)
          Determines which relationship set connection from a given list best corresponds to the outermost nesting level of the given matching context.
protected  Set inferManyMaxRelationships(edu.byu.deg.osmx.OSMXRelSetConnectionType primaryConn, MatchingContext ctxt, Set visitedRelSets)
          Generates a set of relationships for a nested group based on the assumption that the primary connection has a max-many participation constraint.
protected  Set inferNestedRelationships(edu.byu.deg.osmx.OSMXRelSetConnectionType primaryConn, List maxMany, List maxOne, MatchingContext ctxt, Set visitedRelSets)
          Generates a set of relationships for a nested group that contains multiple max-many relationship set connections (one being the primary connection).
protected  edu.byu.deg.osmx.OSMXRelationshipType inferOneMaxRelationship(edu.byu.deg.osmx.OSMXRelSetConnectionType primaryConn, MatchingContext ctxt, Set visitedRelSets)
          Generates a single relationship for a nested group based on the assumption that the primary connection has a max-one participation constraint.
 Set inferRelationships(edu.byu.deg.osmx.OSMXRelSetConnectionType primaryConn, MatchingContext ctxt, Set visitedRelSets)
          The main algorithm for this heuristic.
 void setOntologyIndex(ExtractionOntologyIndex idx)
          Stores a reference to the indexed ontology.
protected  MatchingContext[] subdivideContext(MatchingContext ctxt)
          Divides the given context into multiple matching contexts whose boundaries should approximate the contextual boundaries of the individual objects to be generated for the nested group.
 
Methods inherited from class edu.byu.deg.ontos.MappingHeuristic
addObject, addRelationship, bindObject, getOntologyIndex, getOntologyIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ch

protected ContextualHeuristic ch
Constructor Detail

NestedGroupHeuristic

public NestedGroupHeuristic()
Creates a new instance of NestedGroupHeuristic


NestedGroupHeuristic

public NestedGroupHeuristic(ExtractionOntologyIndex idx)
Creates a new instance of NestedGroupHeuristic and initializes it with an indexed ontology.

Parameters:
idx - An index for the ontology used by the heuristic.
Method Detail

inferRelationships

public Set inferRelationships(edu.byu.deg.osmx.OSMXRelSetConnectionType primaryConn,
                              MatchingContext ctxt,
                              Set visitedRelSets)
The main algorithm for this heuristic. The method generates relationships from the context by greedily invoking ContextualHeuristic recursively until no more objects are produced. A relationship is created for each object returned by ContextualHeuristic, and the set of relationships is returned.

Parameters:
primaryConn - The relationship set connection from which the traversal is originating; in other words, the "side" of the relationship set that the invoking code acted upon to invoke this heuristic. This parameter identifies both the relationship set for which the relationships should be generated, as well as in which direction to continue the recursion.
ctxt - The matching context from which relationships should be generated.
visitedRelSets - A collection of relationship sets previously visited during the recursion; allows us to avoid infinite recursion.
Returns:
A Set of Relationship elements.

setOntologyIndex

public void setOntologyIndex(ExtractionOntologyIndex idx)
Stores a reference to the indexed ontology.

Overrides:
setOntologyIndex in class MappingHeuristic
Parameters:
idx - The ontology index to use during the mapping process.

inferOneMaxRelationship

protected edu.byu.deg.osmx.OSMXRelationshipType inferOneMaxRelationship(edu.byu.deg.osmx.OSMXRelSetConnectionType primaryConn,
                                                                        MatchingContext ctxt,
                                                                        Set visitedRelSets)
Generates a single relationship for a nested group based on the assumption that the primary connection has a max-one participation constraint. Because of the max-one constraint, only one object will be generated for each of the other connections in the relationship set. Each connection must generate an object, though, in order to permit a relationship to be generated.

Parameters:
primaryConn - The connection that defines the relationship set as a max-one nested group. Also indicates from which direction the ontology structure traversal is proceeding.
ctxt - The matching context from which to generate the relationship.
visitedRelSets - Set of relationship sets that have previously been visited. Useful for avoiding infinite recursion.
Returns:
The generated relationship, or null if a relationship could not be generated because objects could not be generated for each of the relationship set connections.

inferManyMaxRelationships

protected Set inferManyMaxRelationships(edu.byu.deg.osmx.OSMXRelSetConnectionType primaryConn,
                                        MatchingContext ctxt,
                                        Set visitedRelSets)
Generates a set of relationships for a nested group based on the assumption that the primary connection has a max-many participation constraint. If all other connections for the relationship set have max-one constraints, the set behaves like an n-ary functional group. In such a case, a relationship is generated each time objects are successfully generated for every non-primary connection. If any other connection is max-many, though, the inferNestedRelationships(edu.byu.deg.osmx.OSMXRelSetConnectionType, java.util.List, java.util.List, edu.byu.deg.ontos.MatchingContext, java.util.Set) method will be invoked, which is more complex in its relationship generation rules.

Parameters:
primaryConn - The relationship set connection that defines the relationship set as a max-many nested group. It also indicates from which direction the traversal of the ontology structure is proceeding.
ctxt - The matching context from which relationships are generated.
visitedRelSets - Set of relationship sets that have previously been visited. Useful for avoiding infinite recursion.
Returns:
A set of Relationship elements that were successfully generated from the given context. The set will be non-null but empty if no relationships were generated.

inferNestedRelationships

protected Set inferNestedRelationships(edu.byu.deg.osmx.OSMXRelSetConnectionType primaryConn,
                                       List maxMany,
                                       List maxOne,
                                       MatchingContext ctxt,
                                       Set visitedRelSets)
                                throws javax.xml.bind.JAXBException
Generates a set of relationships for a nested group that contains multiple max-many relationship set connections (one being the primary connection). In such a case, we assume that concepts represented in the matching context, that will become objects, are expressed in a "nesting" structure. The outermost level is the primary object; it may be associated with multiple objects belonging to a different connection. Each of these objects, in turn, defines its own sub-context containing multiple objects for another connection, and so forth until the lowest level. At this level, if any connections for the nested group relationship set are still unfulfilled by generated objects, the connections must necessarily have max-one constraints and objects are generated from this innermost context—one for each max-one connection. The effect is something like this:
 |--------------- A1 ---------------||--------------- A2 ------------------|
 |--- B1 ---||--- B2 ---||--- B3 ---||-------- B4 ------||------ B5 -------|
 |--- C1 ---|| C2 || C3 || C4 || C5 ||-- C6 --||-- C7 --||------ C8 -------|
 
In this diagram, A is the primary object set, B is an object set at the end of a max-many connection in the nested group, and C is an object set for the remaining connection in the relationship set. Pipes (|) mark context boundaries within which objects (A1, C5, etc.) appear. The overall diagram represents a matching context, and this method's algorithm induces a nesting structure such as the one above upon the input context in order to determine which objects to generate and how to satisfy constraints. The following relationships are generated from the above example: This method invokes itself recursively since the nesting can in theory be arbitrarily deep.

Parameters:
primaryConn - The relationship set connection that defines the relationship set as a max-many nested group. It also indicates from which direction the traversal of the ontology structure is proceeding.
maxMany - A list of the RelSetConnection elements for the nested group which have max-many participation constraints.
maxOne - A list of the RelSetConnection elements for the nested group which have max-one participation constraints.
ctxt - The input context from which relationships are to be inferred.
visitedRelSets - Set of relationship sets that have previously been visited. Useful for avoiding infinite recursion.
Returns:
A set of Relationship elements generated by this method.
Throws:
javax.xml.bind.JAXBException - Thrown if a relationship cannot be generated for some reason.

findOuterMaxMany

protected edu.byu.deg.osmx.OSMXRelSetConnectionType findOuterMaxMany(List maxMany,
                                                                     MatchingContext ctxt)
Determines which relationship set connection from a given list best corresponds to the outermost nesting level of the given matching context.

Parameters:
maxMany - A list of max-many relationship set connections from which the connection for the outermost nesting level should be selected. The list need not contain all max-many connections for the nested group relationship set; rather, it should only contain those max-many connections for which objects still need to be generated from the input matching context.
ctxt - The context over which to induce the nesting structure in order to determine the outermost nesting connection.
Returns:
The connection from the list that best corresponds with the outermost nesting level of the given context.

compareRelSets

protected int compareRelSets(edu.byu.deg.osmx.OSMXRelSetConnectionType r1,
                             edu.byu.deg.osmx.OSMXRelSetConnectionType r2,
                             MatchingContext ctxt)
Defines a total order on a set of relationship set connections by determining, for a pair of such connections, which should precede the other in a sorted list.

Parameters:
r1 - The first relationship set connection to compare.
r2 - The second relationship set connection to compare.
ctxt - The current matching context, which provides information useful in assessing which connection should precede the other.
Returns:
-1 if the first connection should precede the second; or 1 if the second should precede the first. This function does not return 0 unless r1 == r2. This method bases the order only on a dictionary ordering of the IDs of the relationship sets being compared.

subdivideContext

protected MatchingContext[] subdivideContext(MatchingContext ctxt)
Divides the given context into multiple matching contexts whose boundaries should approximate the contextual boundaries of the individual objects to be generated for the nested group. In other words, if the original context would cause multiple objects to be generated, it would be divided into that number of sub-contexts, from each of which an object may be derived.

Parameters:
ctxt - The context to subdivide.
Returns:
An array of matching contexts, each corresponding to an object expected to be generated in the recursive invocation of ContextualHeuristic. Currently this method is not implemented and will throw UnsupportedOperationException if called.

findBestSubContext

protected MatchingContext findBestSubContext(edu.byu.deg.osmx.OSMXRelSetConnectionType conn,
                                             MatchingContext ctxt)
Determines the likely outer boundaries of the nested group from the given context and returns the result as a matching context.

Parameters:
conn - The connection that identifies the nested group.
ctxt - The context from which to derive the nested group context.
Returns:
A matching context that is guaranteed to be a subset of the given context. The method currently returns the same context as is passed in, effectively rendering the method a no-op.