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.
Modifier | Constructor and Description |
---|---|
protected |
KnowledgeChunk()
Empty constructor needed for Hibernate compatibility.
|
|
KnowledgeChunk(String id)
Generates new empty KnowledgeChunk given an identifier.
|
Modifier and Type | Method and Description |
---|---|
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)
Deprecated.
This method has been replaced with the more comprehensible addPredicate.
|
Predicate |
addPredicate(KnowledgeChunk p1,
KnowledgeChunk pn,
KnowledgeChunk valueKc,
String value,
int pathLength,
String valueType,
int valueLength)
Adds a property path to this
KnowledgeChunk object. |
Predicate |
addPredicate(KnowledgeChunk property,
KnowledgeChunk valueKc,
String value,
int pathLength,
String valueType,
int valueLength)
Shortcut for the
addPredicate method when creating predicates with p1 = pn. |
Term |
addTerm(String value,
Double relevance,
Integer frequency)
Add a keyword to this
KnowledgeChunk specifying its relevance and frequency. |
Type |
addType(KnowledgeChunk type)
Overloaded method of the
addType(type, isType) method. |
Type |
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 . |
Term |
getTerm(String value)
Returns the Term having the given
value or null if such Term doesn't exist. |
String |
getTermEquipmentFlat()
Getter for the term equipment flat representation.
|
Set<String> |
getTermEquipmentPlain()
Returns the full term equipment of this object as a
Set of Strings. |
HashSet<Term> |
getTermEquipmentWrapped()
Returns the full term equipment of this object as a
Set of Term
objects. |
Character |
getType()
Getter for the type of this object.
|
Type |
getType(KnowledgeChunk type)
Returns the Type having the given
type or null if such Type doesn't exist. |
Type |
getType(String type)
Returns the Type having the given
type id or null if such Type doesn't exist. |
Set<String> |
getTypesPlain()
Getter for the set of all types identifiers of this kc.
|
Set<Type> |
getTypesWrapped()
Getter for the set of all types of this kc.
|
int |
hashCode()
The hash code for this class is the hash code of its identifier (considered as a string value).
|
Term |
removeTerm(String t)
Removes the keyword
t from this
KnowledgeChunk and returns the removed Term wrapper. |
Term |
removeTerm(Term t)
Remove the term with value
t.getValue() from this kc and returns the removed instance of Term . |
Type |
removeType(KnowledgeChunk type)
Removes the type
type from this
KnowledgeChunk . |
Type |
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.
|
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)
id
- string identifier for the new KnowledgeChunk
KCSessionManager.kcm
protected KnowledgeChunk()
KnowledgeChunk(String id)
instead.id
public Type addType(KnowledgeChunk type)
Overloaded method of the addType(type, isType)
method. In this version isType
is assumed
true.
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.Type
, already associated with this KnowledgeChunk
public Type addType(KnowledgeChunk type, boolean isType)
Add a class (represented by a KnowledgeChunk
instance) to this
KnowledgeChunk
specifying if is an asserted or excluded type.
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
- type
is a declared class of this KnowledgeChunk
type
is a denied class of this KnowledgeChunk
Type
, already associated with this KnowledgeChunk
public Type removeType(String type)
Removes the type represented by the id type
from this
KnowledgeChunk
.
type
- the type (a String value representing the identifier of the type) to be removed. If type
is a null, a void value or it doesn't exists in this kc it will be ignored raising a warning message.type
was not associated to this kc, the removed type (class Type) otherwise.public Type removeType(KnowledgeChunk type)
Removes the type type
from this
KnowledgeChunk
.
type
- the type (a KnowledgeChunk of type 'C') to be removed. If type
is a null value or it doesn't exists in this kc it will be ignored raising a warning message.type
was not associated to this kc, the removed type (class Type) otherwise.public Type getType(String type)
type
id or null if such Type doesn't exist.type
- the type name of the required Type.Type
) associated with the id type
.public Type getType(KnowledgeChunk type)
type
or null if such Type doesn't exist.type
- the KnowledgeChunk of type 'C' of the required Type.Type
) associated with the class type
.public Set<String> getTypesPlain()
Getter for the set of all types identifiers of this kc.
String
s.public Set<Type> getTypesWrapped()
Getter for the set of all types of this kc.
Type
public Term addTerm(String value, Double relevance, Integer frequency)
Add a keyword to this
KnowledgeChunk
specifying its relevance and frequency.
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
.Sfrequency
- the frequency of the added keyword in the terminological equipment of this
KnowledgeChunk
, expressed as the number of its occurrences.Term
, already associated with this KnowledgeChunk
public Term removeTerm(String t)
Removes the keyword t
from this
KnowledgeChunk
and returns the removed Term wrapper.
t
- the keyword to be removed. If t
is a null or a void value it will be ignored raising a warning message.public Term removeTerm(Term t)
t.getValue()
from this kc and returns the removed instance of Term
.
If such a term does not exist returns null and prints a warning message.t
- the term with the value that should be removed from the terminological equipment of this KnowledgeChunk.t
, the removed term otherwise.public Term getTerm(String value)
value
or null if such Term doesn't exist.value
- the value of the required Term.Term
) associated with the keyword value
.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).
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.Predicate
Predicate
,
addPredicate(KnowledgeChunk, KnowledgeChunk, KnowledgeChunk, String, int, String, int)
public Predicate addPredicate(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).
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.Predicate
Predicate
public Predicate addPredicate(KnowledgeChunk property, KnowledgeChunk valueKc, String value, int pathLength, String valueType, int valueLength)
addPredicate
method when creating predicates with p1 = pn.property
- The KnowledgeChunk
that will represent p1 AND pn.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.Predicate
addPredicate(KnowledgeChunk, KnowledgeChunk, KnowledgeChunk, String, int, String, int)
public void addDocument(Document doc)
Adds a source document to this KnowledgeChunk
instance.
doc
- the document to be addedpublic Set<Document> getDocuments()
Retrieves all the documents which this kc belongs to.
public HashSet<Term> getTermEquipmentWrapped()
Returns the full term equipment of this object as a Set
of Term
objects.
Type
.Term
public Set<String> getTermEquipmentPlain()
Returns the full term equipment of this object as a Set
of Strings.
objects.
Term
public String toString()
public int hashCode()
public String getId()
Getter for the identifier of this class.
KnowledgeChunk
public String getName()
Getter for the name representation of this KnowledgeChunk
. Usually the name of the
represented object.
KnowledgeChunk
.public void setName(String name)
Setter for the name representation of this KnowledgeChunk
.
name
- the name of this KnowledgeChunk
.public void setGlobal(Boolean global)
public Boolean getGlobal()
public Set<Predicate> getLinks()
Getter for the set of predicates having this node as a belongKc
.
public Set<DocumentExtraction> getExtractedFrom()
Getter for the list of document where this kc belongs.
public void setType(Character type)
Setter for the type of this object. It could be
type
- a character representing the type of this object.public Character getType()
Getter for the type of this object. It could be
public void setTermEquipmentFlat(String terEq)
Setter for the term equipment flat representation. This is a list of comma separated words.
terEq
- the comma separated list of words representing the term equipment of this object.public String getTermEquipmentFlat()
Getter for the term equipment flat representation. This is a list of comma separated words.