edu.uchsc.ccp.knowtator
Class MentionUtil

java.lang.Object
  extended by edu.uchsc.ccp.knowtator.MentionUtil

public class MentionUtil
extends Object


Constructor Summary
MentionUtil(KnowtatorProjectUtil kpu)
          Creates a new instance of MentionUtil
 
Method Summary
 void addInverse(SimpleInstance annotationMention, Slot mentionSlot, SimpleInstance mentionSlotValueMention)
          This method was written and contributed by Angus Roberts.
 void addSlotMention(SimpleInstance mention, SimpleInstance slotMention)
          This method adds a slotMention to a class or instance mention.
 void addValueToSlotMention(SimpleInstance slotMention, Object slotValue)
          This method adds a value to a slotMention.
 void adjustSlotMentionForCardinality(Cls cls, Slot slot, SimpleInstance mention)
           
 SimpleInstance copyMention(SimpleInstance mention, Map<SimpleInstance,SimpleInstance> copiesMap)
           
 SimpleInstance createClassMention(Cls cls)
           
 SimpleInstance createInstanceMention(SimpleInstance simpleInstance)
           
 SimpleInstance createMention(Instance instance)
          Creates a mention based on the passed in instance.
 SimpleInstance createSlotMention(Slot slot)
           
 void deleteMention(SimpleInstance mention)
           
 boolean equals(SimpleInstance mention1, SimpleInstance mention2, boolean compareAnnotationSpans)
           
 Set<SimpleInstance> getAllConnectedMentions(SimpleInstance mention)
          This method gathers all the mentions (e.g.
 List<SimpleInstance> getComplexSlotMentions(SimpleInstance mention)
          This method gets the complex slot mentions of a class mention or instance mention.
 SimpleInstance getMentionAnnotation(SimpleInstance mention)
           
 Cls getMentionCls(SimpleInstance mention)
          If the mention is a "class mention" then the Cls corresponding to the mentioned class is returned.
 SimpleInstance getMentionedBy(SimpleInstance slotMention)
           
 Frame getMentionFrame(SimpleInstance mention)
           
 SimpleInstance getMentionInstance(SimpleInstance instanceMention)
           
 List<Slot> getMentionSlots(SimpleInstance mention)
           
 List<SimpleInstance> getRelatedMentions(SimpleInstance mention)
          This method returns all class mentions or instance mentions related to the passed in mention via slot mentions.
 List<SimpleInstance> getRelatedMentions(SimpleInstance mention, Slot slot)
          This method returns all class mentions or instance mentions related to the passed in mention via slot mentions whose mentioned slot is the passed in slot.
 List<SimpleInstance> getSlotFillerCandidates(SimpleInstance mention, Slot slot, List<SimpleInstance> annotations)
           
 SimpleInstance getSlotMention(SimpleInstance mention, Slot mentionSlot)
          gets a slot mention for the given slot of a class mention or instance mention.
 List<SimpleInstance> getSlotMentions(SimpleInstance mention)
          This method gets the slot mentions of a class mention or instance mention.
 Slot getSlotMentionSlot(SimpleInstance mention)
           
 List<Object> getSlotMentionValues(SimpleInstance slotMention)
           
 boolean hasSlotMention(SimpleInstance mention, Slot mentionSlot)
           
 boolean hasSlotValue(SimpleInstance slotMention)
           
 void initializeSlotMentions(SimpleInstance mention)
          this method takes a mention and initializes slot mentions for slots that do not yet have a slotMention for the mention.
 boolean isBooleanSlotMention(SimpleInstance mention)
           
 boolean isClassMention(SimpleInstance mention)
           
 boolean isComplexSlotMention(SimpleInstance mention)
          Determines whether an instance is a complex slot mention.
 boolean isFloatSlotMention(SimpleInstance mention)
           
 boolean isInstanceMention(SimpleInstance mention)
           
 boolean isIntegerSlotMention(SimpleInstance mention)
           
 boolean isMention(SimpleInstance mention)
           
 boolean isSimpleSlotMention(SimpleInstance mention)
           
 boolean isSlotMention(SimpleInstance mention)
           
 boolean isStringSlotMention(SimpleInstance mention)
           
 void removeEmptySlotMentions(SimpleInstance mention)
           
 void removeInverse(SimpleInstance annotationMention, Slot mentionSlot, SimpleInstance mentionSlotValueMention)
          This method was written and contributed by Angus Roberts.
 void removeValueFromSlotMention(SimpleInstance slotMention, Object slotValue)
           
 void setAnnotationUtil(AnnotationUtil annotationUtil)
           
 void setMentionAnnotations(SimpleInstance mention, Collection<SimpleInstance> annotations)
           
 void setMentionCls(SimpleInstance clsMention, Cls mentionCls)
          This method sets the cls that is mentioned by a class mention.
 void setMentionInstance(SimpleInstance instanceMention, SimpleInstance mentionInstance)
          This method sets the instance that is mentioned by an instance mention.
 void setMentionSlot(SimpleInstance slotMention, Slot mentionSlot)
          This method sets the slot that is mentioned by a slot mention.
 void setSlotMentionValues(SimpleInstance slotMention, List<Object> values)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MentionUtil

public MentionUtil(KnowtatorProjectUtil kpu)
Creates a new instance of MentionUtil

Method Detail

setAnnotationUtil

public void setAnnotationUtil(AnnotationUtil annotationUtil)

equals

public boolean equals(SimpleInstance mention1,
                      SimpleInstance mention2,
                      boolean compareAnnotationSpans)

copyMention

public SimpleInstance copyMention(SimpleInstance mention,
                                  Map<SimpleInstance,SimpleInstance> copiesMap)
Parameters:
mention -
copiesMap -
Returns:
TODO simplify the signature.

createClassMention

public SimpleInstance createClassMention(Cls cls)

createInstanceMention

public SimpleInstance createInstanceMention(SimpleInstance simpleInstance)

addSlotMention

public void addSlotMention(SimpleInstance mention,
                           SimpleInstance slotMention)
This method adds a slotMention to a class or instance mention. Please refer to the knowtator model in knowtator.pprj and look at the class definition for "knowtator class mention". This method adds a value to the slot 'knowtator_slot_mention'.

See Also:
addValueToSlotMention(SimpleInstance, Object)

addValueToSlotMention

public void addValueToSlotMention(SimpleInstance slotMention,
                                  Object slotValue)
This method adds a value to a slotMention. Please refer to the knowtator model in knowtator.pprj and look at the class definition for "knowtator slot mention". This method adds a value to the slot 'knowtator_mention_slot_value'.

Parameters:
slotMention - must be an instance of a slot mention
slotValue - can be a class mention, instance mention, or an Integer, Float, String or Boolean.

removeValueFromSlotMention

public void removeValueFromSlotMention(SimpleInstance slotMention,
                                       Object slotValue)

createSlotMention

public SimpleInstance createSlotMention(Slot slot)

createMention

public SimpleInstance createMention(Instance instance)
Creates a mention based on the passed in instance. Instance is the super interface for Cls, SimpleInstance and Slot. Depending on the Class of the passed instance, the return value will be a "class mention", "instance mention" or "slot mention".

Parameters:
instance - should be Cls, SimpleInstance or Slot
Returns:
null - if instance is not a Cls, SimpleInstance or Slot. Otherwise, returns a "class mention", "instance mention", or "slot mention"

isClassMention

public boolean isClassMention(SimpleInstance mention)

isInstanceMention

public boolean isInstanceMention(SimpleInstance mention)

isMention

public boolean isMention(SimpleInstance mention)

isSlotMention

public boolean isSlotMention(SimpleInstance mention)

isBooleanSlotMention

public boolean isBooleanSlotMention(SimpleInstance mention)

isFloatSlotMention

public boolean isFloatSlotMention(SimpleInstance mention)

isIntegerSlotMention

public boolean isIntegerSlotMention(SimpleInstance mention)

isStringSlotMention

public boolean isStringSlotMention(SimpleInstance mention)

isSimpleSlotMention

public boolean isSimpleSlotMention(SimpleInstance mention)

isComplexSlotMention

public boolean isComplexSlotMention(SimpleInstance mention)
Determines whether an instance is a complex slot mention. Please refer to the knowtator model in knowtator.pprj and look at the class definition for "knowtator complex slot mention". If the instance is of type "knowtator complex slot mention" of one of its descendants, then true is returned.

Returns:
true if the instance is of type "knowtator complex slot mention".

getAllConnectedMentions

public Set<SimpleInstance> getAllConnectedMentions(SimpleInstance mention)
This method gathers all the mentions (e.g. slot mentions, class mentions and instance mentions) that are connected to the passed in mention. Connections are directed and start from the passed in mention and are found recursively via slot mentions. For example, if a class mention is passed in, then its slot mentions, the mention values of the slot mentions, and their slot mentions (and so on) will all be in the returned set. The returned set does not parallel the structure of the relationships between the mentions - it simply gathers them up and dumps in the returned set. The returned set contains the mention that is passed to the method.

Parameters:
mention - should be a Protege instance of mention.
Returns:
if mention is not a Protege instance of mention, then an empty set will be returned. Otherwise, the set will contain the passed in mention and all mentions (class, instance, and slot) that it is connected to (see above.)

getRelatedMentions

public List<SimpleInstance> getRelatedMentions(SimpleInstance mention)
This method returns all class mentions or instance mentions related to the passed in mention via slot mentions. This method returns all of the complex slot mention values for a class mention or instance mention. Please refer to the knowtator model in knowtator.pprj and look at the class definition for "knowtator class mention" or "knowtator instance mention". The values of the slot "knowtator_slot_mention" may be of type "knowtator complex slot mention". Values of the slot "knowtator_mention_slot_value" for values of the passed in mentions values of the slot "knowtator_slot_mention" are returned.

Parameters:
mention - should be of type 'knowtator class mention' or 'knowtator instance mention'.
Returns:
the slot mention values of the mention's slot mentions. All values in the returned list should be of type 'knowtator class mention' or 'knowtator instance mention'. This method will return an empty list if there are no related mentions or if the mention is not a class mention or instance mention.

getRelatedMentions

public List<SimpleInstance> getRelatedMentions(SimpleInstance mention,
                                               Slot slot)
This method returns all class mentions or instance mentions related to the passed in mention via slot mentions whose mentioned slot is the passed in slot. Please refer to the knowtator model in knowtator.pprj and look at the class definition for "knowtator class mention" or "knowtator instance mention". The values of the slot "knowtator_slot_mention" may be of type "knowtator complex slot mention". Values of the slot "knowtator_mention_slot_value" for values of the passed in mention's values of the slot "knowtator_slot_mention" are returned if the slot mention's "knowtator_mention_slot" is the same as the passed in slot.

Parameters:
mention - should be of type 'knowtator class mention' or 'knowtator instance mention'.
slot - a slot corresponding to a knowtator_mention_slot of a 'knowtator complex slot mention'
Returns:
All values in the returned list should be of type 'knowtator class mention' or 'knowtator instance mention'. This method will return an empty list if there are no related mentions or if the mention is not a class mention or instance mention.

getMentionFrame

public Frame getMentionFrame(SimpleInstance mention)

getMentionCls

public Cls getMentionCls(SimpleInstance mention)
If the mention is a "class mention" then the Cls corresponding to the mentioned class is returned. If the mention is a "instance mention" then the Cls corresponding to the direct type of the mentioned instance is returned.

Returns:
the class of a class mention, or the direct type of the instance of an instance mention or null if the class or instance no longer exists

setMentionCls

public void setMentionCls(SimpleInstance clsMention,
                          Cls mentionCls)
This method sets the cls that is mentioned by a class mention. Please refer to the knowtator model in knowtator.pprj and look at the class definition for "knowtator class mention". This method sets the value for the slot "knowtator_mention_class".

Parameters:
clsMention - the mention must be a class mention or this method does nothing
mentionCls - the class that is mentioned by the instance mention

setMentionInstance

public void setMentionInstance(SimpleInstance instanceMention,
                               SimpleInstance mentionInstance)
This method sets the instance that is mentioned by an instance mention. Please refer to the knowtator model in knowtator.pprj and look at the class definition for "knowtator instance mention". This method sets the value for the slot "knowtator_mention_instance".

Parameters:
instanceMention - the mention must be an instance mention or this method does nothing
mentionInstance - the instance that is mentioned by the instance mention

setMentionSlot

public void setMentionSlot(SimpleInstance slotMention,
                           Slot mentionSlot)
This method sets the slot that is mentioned by a slot mention. Please refer to the knowtator model in knowtator.pprj and look at the class definition for "knowtator slot mention". This method sets the value for the slot "knowtator_mention_slot".

Parameters:
slotMention - the mention must be a slot mention or this method does nothing
mentionSlot - the slot that is mentioned by the slot mention

getMentionInstance

public SimpleInstance getMentionInstance(SimpleInstance instanceMention)

getSlotMentions

public List<SimpleInstance> getSlotMentions(SimpleInstance mention)
This method gets the slot mentions of a class mention or instance mention. Please refer to the knowtator model in knowtator.pprj and look at the class definition for "knowtator class mention" or "knowtator instance mention". This method returns the values of the slot "knowtator_slot_mention".

Parameters:
mention - must be a class mention or instance mention otherwise an empty list will be returned
Returns:
all slot mentions for the mention. If none exist, then an empty list will be returned.

getComplexSlotMentions

public List<SimpleInstance> getComplexSlotMentions(SimpleInstance mention)
This method gets the complex slot mentions of a class mention or instance mention. Please refer to the knowtator model in knowtator.pprj and look at the class definition for "knowtator class mention" or "knowtator instance mention". This method returns the values of the slot "knowtator_slot_mention" that are of type "knowtator complex slot mention".

Parameters:
mention - should be a class mention or instance mention;
Returns:
all complex slot mentions for the mention. If none exist, then an empty list will be returned.

getMentionSlots

public List<Slot> getMentionSlots(SimpleInstance mention)

getSlotMention

public SimpleInstance getSlotMention(SimpleInstance mention,
                                     Slot mentionSlot)
gets a slot mention for the given slot of a class mention or instance mention. Please refer to the knowtator model in knowtator.pprj and look at the class definition for "knowtator class mention" or "knowtator instance mention". This method returns the values of the slot "knowtator_slot_mention" that correspond to the passed in slot.

Parameters:
mention - must be a class mention or instance mention otherwise null will be returned.
mentionSlot - the "knowtator_mention_slot" of the slot mention.
Returns:
an instance of 'knowtator slot mention' or one of its subtypes or null if none exist.

hasSlotMention

public boolean hasSlotMention(SimpleInstance mention,
                              Slot mentionSlot)

hasSlotValue

public boolean hasSlotValue(SimpleInstance slotMention)

initializeSlotMentions

public void initializeSlotMentions(SimpleInstance mention)
this method takes a mention and initializes slot mentions for slots that do not yet have a slotMention for the mention.


removeEmptySlotMentions

public void removeEmptySlotMentions(SimpleInstance mention)

deleteMention

public void deleteMention(SimpleInstance mention)

getMentionAnnotation

public SimpleInstance getMentionAnnotation(SimpleInstance mention)

setMentionAnnotations

public void setMentionAnnotations(SimpleInstance mention,
                                  Collection<SimpleInstance> annotations)

getSlotMentionSlot

public Slot getSlotMentionSlot(SimpleInstance mention)

getSlotMentionValues

public List<Object> getSlotMentionValues(SimpleInstance slotMention)

setSlotMentionValues

public void setSlotMentionValues(SimpleInstance slotMention,
                                 List<Object> values)

getMentionedBy

public SimpleInstance getMentionedBy(SimpleInstance slotMention)

addInverse

public void addInverse(SimpleInstance annotationMention,
                       Slot mentionSlot,
                       SimpleInstance mentionSlotValueMention)
This method was written and contributed by Angus Roberts. This method takes a mention slot with a known value on an annotation mention, and adds an inverse slot on the value, with the annotation mentions as its valu. If the inverse slot does not exist, it is added. Given annotationMention--[mentionSlot]--mentionSlotValueMention, the method will add mentionSlotValueMention--[inverse_of_mentionSlot]--annotationMention

Parameters:
annotationMention - an annotation mention with a mention slot
mentionSlot - a slot, the inverse of which will be added
mentionSlotValueMention - the value of that will be added to mentionSlot

removeInverse

public void removeInverse(SimpleInstance annotationMention,
                          Slot mentionSlot,
                          SimpleInstance mentionSlotValueMention)
This method was written and contributed by Angus Roberts. This method takes a mention slot with a known value on an annotation mention, and checks for an inverse slot on the value. If the inverse exists, it is removed. Given annotationMention--[mentionSlot]--mentionSlotValueMention, the method will remove mentionSlotValueMention--[inverse_of_mentionSlot]--annotationMention

Parameters:
annotationMention - an annotation mention with a mention slot
mentionSlot - a slot, the inverse of which will be removed
mentionSlotValueMention - the value of mentionSlot

getSlotFillerCandidates

public List<SimpleInstance> getSlotFillerCandidates(SimpleInstance mention,
                                                    Slot slot,
                                                    List<SimpleInstance> annotations)

adjustSlotMentionForCardinality

public void adjustSlotMentionForCardinality(Cls cls,
                                            Slot slot,
                                            SimpleInstance mention)