it.unimi.dico.islab.idbs2.kc
Class KnowledgeChunk

java.lang.Object
  extended by it.unimi.dico.islab.idbs2.kc.KnowledgeChunk

public class KnowledgeChunk
extends Object

Main class of the kc framework, representation of a knowledge chunk. A kc is unit of knowledge, the representation of an object, type or property of the context of interest. It is composed by a list of types, a terminological equipment (a list of terms with associated frequency value and relevance value), a set of predicates (i.e. a set of property paths with associated object/value), a type (i.e. {C, P, I}, as Class, Property or Instance) and a connected Document, source of the extraction process.

The following image shows the relations between the fields of this object and the fields of the wrapped database table (fields with the same color represents a mapping between relational schema and the corresponding object).


This class also supplies methods for Hibernate database wrapper management.

Author:
Vegeziel
See Also:
Document, Predicate, Term, Type

Constructor Summary
protected KnowledgeChunk()
          Empty constructor needed for Hibernate compatibility.
  KnowledgeChunk(String id)
          Generates new empty KnowledgeChunk given an identifier.
 
Method Summary
 void addDocument(Document doc)
          Adds a source document to this KnowledgeChunk instance.
 Predicate addLink(KnowledgeChunk p1, KnowledgeChunk pn, KnowledgeChunk valueKc, String value, int pathLength, String valueType, int valueLength)
          Adds a property path to this KnowledgeChunk object.
 void addTerm(String value, Double relevance, Integer frequency)
          Add a keyword to this KnowledgeChunk specifying its relevance and frequency.
 void addType(KnowledgeChunk type)
          Overload of the addType(type, isType) method.
 void addType(KnowledgeChunk type, boolean isType)
          Add a class (represented by a KnowledgeChunk instance) to this KnowledgeChunk specifying if is an asserted or excluded type.
 boolean equals(Object o)
           
 Set<Document> getDocuments()
          Retrieves all the documents which this kc belongs to.
 Set<DocumentExtraction> getExtractedFrom()
          Getter for the list of document where this kc belongs.
 Boolean getGlobal()
           
 String getId()
          Getter for the identifier of this class.
 Set<Predicate> getLinks()
          Getter for the set of predicates having this node as a belongKc.
 String getName()
          Getter for the name representation of this KnowledgeChunk.
 Set<Term> getTermEquipment()
           Getter for the full term equipment of this object.
 String getTermEquipmentFlat()
          Getter for the term equipment flat representation.
 Character getType()
          Getter for the type of this object.
 Set<Type> getTypes()
          Getter for the set of all types of this kc.
 int hashCode()
           
 void removeTerm(String t)
          Removes the keyword t from this KnowledgeChunk.
 void removeType(KnowledgeChunk t)
          Removes the type t from this KnowledgeChunk.
 void removeType(String type)
          Removes the type represented by the id type from this KnowledgeChunk.
 void setGlobal(Boolean global)
           
 void setName(String name)
          Setter for the name representation of this KnowledgeChunk.
 void setTermEquipmentFlat(String terEq)
          Setter for the term equipment flat representation.
 void setType(Character type)
          Setter for the type of this object.
 String toString()
          Give a textual representation of this object in form of its identifier.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

KnowledgeChunk

public KnowledgeChunk(String id)

Generates new empty KnowledgeChunk given an identifier.

N.B.: A new instance of KnowledgeChunk will be in a detached state (see Hibernate reference manual for more details about object states) until an explicit request (like a save operation). If a KnowledgeChunk with the same primary key will already be present on the wrapped database, an exception will be thrown while trying to save this new instance. In order to reload an existing KnowledgeChunk use KCManager.getKnowledgeChunkById(String)

Parameters:
id - string identifier for the new KnowledgeChunk
See Also:
KCSessionManager.kcm

KnowledgeChunk

protected KnowledgeChunk()
Empty constructor needed for Hibernate compatibility. Direct usage is discouraged, use KnowledgeChunk(String id) instead.

See Also:
id
Method Detail

addType

public void addType(KnowledgeChunk type)

Overload of the addType(type, isType) method. In this version isType is assumed true.

Parameters:
type - a KnowledgeChunk to be added as a type for this object. If type is a null value it will be ignored raising a warning message.

addType

public void addType(KnowledgeChunk type,
                    boolean isType)

Add a class (represented by a KnowledgeChunk instance) to this KnowledgeChunk specifying if is an asserted or excluded type.

Parameters:
type - a KnowledgeChunk to be added as a type (or as a "is not type") for this object. If type is a null value it will be ignored raising a warning message.
isType -
  • true: type is a declared class of this KnowledgeChunk
  • false: type is a denied class of this KnowledgeChunk

removeType

public void removeType(String type)

Removes the type represented by the id type from this KnowledgeChunk.

Parameters:
type - the type (a String value representing the identifier of the type) to be removed. If t is a null or a void value it will be ignored raising a warning message.

removeType

public void removeType(KnowledgeChunk t)

Removes the type t from this KnowledgeChunk.

Parameters:
t - the type (KnowledgeChunk of type 'T') to be removed. If t is a null value it will be ignored raising a warning message.

addTerm

public void addTerm(String value,
                    Double relevance,
                    Integer frequency)

Add a keyword to this KnowledgeChunk specifying its relevance and frequency.

Parameters:
value - the keyword to be added. If value is a null value it will be ignored raising a warning message.
relevance - the relevance of the added keyword for this KnowledgeChunk.S
frequency - the frequency of the added keyword in the terminological equipment of this KnowledgeChunk, expressed as the number of its occurrences.

removeTerm

public void removeTerm(String t)

Removes the keyword t from this KnowledgeChunk.

Parameters:
t - the keyword to be removed. If t is a null or a void value it will be ignored raising a warning message.

addLink

public Predicate addLink(KnowledgeChunk p1,
                         KnowledgeChunk pn,
                         KnowledgeChunk valueKc,
                         String value,
                         int pathLength,
                         String valueType,
                         int valueLength)

Adds a property path to this KnowledgeChunk object. The property path is represented by a Predicate instance starting from the current object (that will be the belongKc value).

Parameters:
p1 - a KnowledgeChunk representing the first edge (property) in the path.
pn - a KnowledgeChunk representing the last edge (property) in the path.
valueKc - a KnowledgeChunk representing the final object of the property path.
value - a literal that is the value of the last object of the path.
pathLength - the number of edges in the path.
valueType - string representation for the data type of the value field.
valueLength - length of the value field, materialized for efficiency reasons.
Returns:
the generated Predicate
See Also:
Predicate

addDocument

public void addDocument(Document doc)

Adds a source document to this KnowledgeChunk instance.

Parameters:
doc - the document to be added

getDocuments

public Set<Document> getDocuments()

Retrieves all the documents which this kc belongs to.

Returns:
the documents which this kc belongs to.

toString

public String toString()
Give a textual representation of this object in form of its identifier.

Overrides:
toString in class Object
Returns:
a String representing the identifier of this object.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getId

public String getId()

Getter for the identifier of this class.

Returns:
the string identifier of this KnowledgeChunk

getName

public String getName()

Getter for the name representation of this KnowledgeChunk. Usually the name of the represented object.

Returns:
the name of this KnowledgeChunk.

setName

public void setName(String name)

Setter for the name representation of this KnowledgeChunk.

Parameters:
name - the name of this KnowledgeChunk.

setGlobal

public void setGlobal(Boolean global)

getGlobal

public Boolean getGlobal()

getLinks

public Set<Predicate> getLinks()

Getter for the set of predicates having this node as a belongKc.

Returns:
a set of predicates.

getExtractedFrom

public Set<DocumentExtraction> getExtractedFrom()

Getter for the list of document where this kc belongs.

Returns:
a set of objects representing the extraction of this kc from a document.

setType

public void setType(Character type)

Setter for the type of this object. It could be

Parameters:
type - a character representing the type of this object.

getType

public Character getType()

Getter for the type of this object. It could be

Returns:
a character representing the type of this object.

setTermEquipmentFlat

public void setTermEquipmentFlat(String terEq)

Setter for the term equipment flat representation. This is a list of comma separated words.

Parameters:
terEq - the comma separated list of words representing the term equipment of this object.

getTermEquipmentFlat

public String getTermEquipmentFlat()

Getter for the term equipment flat representation. This is a list of comma separated words.

Returns:
terEq the comma separated list of words representing the term equipment of this object.

getTermEquipment

public Set<Term> getTermEquipment()

Getter for the full term equipment of this object. This field is a Set of Term objects

Returns:
the set of all terms belonging to the term equipment of this kc, wrapped in a special class Type.
See Also:
Term

getTypes

public Set<Type> getTypes()

Getter for the set of all types of this kc.

Returns:
the set of all types of this kc.
See Also:
Type