fleXplorer.Taxonomies
Class Taxonomy<Type extends FacetsType>

java.lang.Object
  extended by fleXplorer.Terminologies.Terminology<Type>
      extended by fleXplorer.Taxonomies.Taxonomy<Type>
Type Parameters:
Type - Generic Type. Taxonomy can include only one type of Terms. Type can be int, String, Date, Interval ...
All Implemented Interfaces:
ITaxonomy<Type>, ITerminology<Type>, java.lang.Cloneable

public class Taxonomy<Type extends FacetsType>
extends Terminology<Type>
implements ITaxonomy<Type>, java.lang.Cloneable

Version:
1.1
Author:
Nikos

Constructor Summary
Taxonomy()
          Constructs a Taxonomy that doesn't checks the relationships of the Terms, the Terms are comparable, Taxonomy has an hierarchy and the Java type of terms are String.
Taxonomy(java.lang.String taxName)
          Constructs a Taxonomy with specified name and doesn't checks the relationships of the Terms, the Terms are comparable, Taxonomy has an hierarchy and the Java type of terms are String..
Taxonomy(java.lang.String name, CheckRel checkRel, Comparison comparability, HasLists hasLists, java.lang.String type)
          Constructs a Taxonomy with the specified name, comparability and check of relationships and defines if the Taxonomy has hierarchy or it is flat.
Taxonomy(Taxonomy<Type> tx)
          Constructs a Taxonomy object with the same properties as the argument.
 
Method Summary
 int addHead(FacetsType head)
          Add a head term at the taxonomy.
 boolean checkRel()
          Return the value of variable that defines when will be the check for cycles and redundant relationships.
 void clear()
          Removes all relationships and terms from the taxonomy.
 boolean containsChild(int parentId, FacetsType childValue)
          Return true if the term with the specified id has a direct child with the specified value.
 boolean containsChild(int parentId, int childId)
          Return true if the term with the specified id has a direct child with the specified id.
 boolean containsParent(int childId, FacetsType parentValue)
          Return true if the term with the specified id has a direct parent with the specified value.
 boolean containsParent(int childId, int parentId)
          Return true if the term with the specified id has a direct parent with the specified id.
 int directChildrenSize(int parentId)
          Returns the number of the direct children of the Term with the specified id.
 int directChildrenSize(Term<FacetsType> parent)
          Returns the number of the direct children of the specified term.
 int directParentsSize(int childId)
          Returns the number of the direct parents of the Term with the specified id.
 int directParentsSize(Term<FacetsType> child)
          Returns the number of the direct parents of the specified Term.
 void elimRR()
          Eliminates redundant relationships.
 java.util.ArrayList<Term<FacetsType>> getAllChildren(Term<FacetsType> parent)
          Returns all children of the specified term.
 java.util.HashSet<java.lang.Integer> getAllIds(int termId)
          Returns all ids of the documents that is indexed to the term with the specified id and all its descendants.
 java.util.HashSet<java.lang.Integer> getAllIds(Term<FacetsType> term)
          Returns all ids of the documents that is indexed to the specified term and all its descendants.
 java.util.Collection<Term<FacetsType>> getAllParents(int childId)
          Returns all parents of the specified term.
 java.util.ArrayList<Term<FacetsType>> getAllParents(Term<FacetsType> child)
          Returns all parents of the specified term.
 java.util.HashMap<java.lang.Integer,java.util.Collection<Term<FacetsType>>> getAllParentsWithHierarchy(Term<FacetsType> child)
          Returns a HashMap with all parents of the specified term using hierarchy.
 java.util.Map<Term<FacetsType>,java.util.Collection<Term<FacetsType>>> getAllRelations()
          Returns a Map with all relationships of the taxonomy.
 int getChildId(int parentId, FacetsType childValue)
          Returns the id of the child term with the specified value of the parent term with the specified id.
 java.util.HashMap<Term<FacetsType>,java.lang.Integer> getCount(java.util.HashSet<java.lang.Integer> indexes)
          Returns the count information for all Terms of the flat Taxonomy according to the indexes.
 int getCount(int termId, java.util.HashSet<java.lang.Integer> indexes)
          Returns the count information of the Term with the specified id according to the indexes.
 int getCount(Term<FacetsType> term, java.util.HashSet<java.lang.Integer> indexes)
          Returns the count information of the specified Term according to the indexes.
 java.util.Collection<Term<FacetsType>> getDirectChildren(int parentId)
          Returns the direct children of the Term with the specified id.
 java.util.Collection<Term<FacetsType>> getDirectChildren(Term<FacetsType> parent)
          Returns the direct children of the specified Term.
 java.util.Collection<Term<FacetsType>> getDirectParents(int childId)
          Returns the direct parents of the Term with the specified id.
 java.util.Collection<Term<FacetsType>> getDirectParents(Term<FacetsType> child)
          Returns the direct parents of the specified Term.
 Term<FacetsType> getHead()
          Returns the head term of the taxonomy if taxonomy is not flat else returns the top element.
 java.lang.String getName()
          Returns the name of Taxonomy.
 int getNumOfRelations()
          Returns the number of relations of the taxonomy.
 int getTermId(java.lang.String path)
          Returns the id of the term that described by the specified id.
 java.lang.String getTermPath(int tid)
          Returns the path of the term with the specific id.
 Term<FacetsType> getTopElement()
          Returns the top element.
 int getTopElementId()
          Returns the id of the top element.
 java.lang.String getType()
          Returns the Java type of the Terms of the Taxonomy.
 Validation getValidation()
          Returns if taxonomy is valid.
 boolean hasLists()
          Returns the value of variable that defines if Taxonomy's Terms have lists for its parents and children.
 boolean isBroader(int parentId, int childId)
          Checks if a term is broader that an other (subsumption checking).
 boolean isChild(Term<FacetsType> parent, Term<FacetsType> child)
          Checks if the second argument is a child of the first one.
 boolean isCycle(Term<FacetsType> parent, Term<FacetsType> child)
          Checks if this relationship parent - child causes a cycle to Taxonomy's graph.
 boolean isDirectChild(Term<FacetsType> parent, Term<FacetsType> child)
          Checks if the second argument is direct child of the first one.
 boolean isDirectParent(Term<FacetsType> child, Term<FacetsType> parent)
          Checks if the second argument is direct parent of the first one.
 boolean isNarrower(int parentId, int childId)
          Checks if a term is broader that an other (subsumption checking).
 boolean isParent(Term<FacetsType> child, Term<FacetsType> parent)
          Checks if the second term is a parent of the first one.
 boolean isRR(Term<FacetsType> parent, Term<FacetsType> child)
          Checks if this relationship parent - child is redundant.
 boolean isValid()
          Search for cycles in Taxonomy.
 boolean isZP(int termId, java.util.HashSet<java.lang.Integer> indexes)
          Returns true if the term with the specified id is a legal term according the list of documents(objects) that have to be presented(indexes).
 void printDirectChildren(Term<Type> parent)
          Prints the direct children of the specified term.
 void printDirectParents(Term<Type> child)
          Prints the direct parents of the specified term.
 void removeAllTheOtherIndexes(int termId)
          If the taxonomy is not flat, removes the indexes of all terms of the taxonomy except the indexes of the term with the specified id and all of its descendants.
 boolean removeDirectChild(Term<FacetsType> parent, Term<FacetsType> child)
          Removes the child Term of the specified parent Term with the specified value.
 boolean removeDirectParent(Term<FacetsType> child, Term<FacetsType> parent)
          Removes the parent Term of the specified child Term with the specified value.
 boolean removeRelship(int parentId, int childId)
          Removes the relationship between two terms.
 boolean removeRelship(Term<FacetsType> parent, Term<FacetsType> child)
          Removes the relationship between two terms.
 void setCheckRel(CheckRel checkRel)
          Sets the value of variable that defines when will be the check for cycles and redundant relationships.
 void setHasLists(HasLists value)
          Sets the value of variable that defines if the taxonomy is flat or there is a hierarchy.
 void setName(java.lang.String name)
          Defines the name of Taxonomy.
 java.util.HashMap<java.lang.String,java.lang.Integer> setRelship(FacetsType parentValue, FacetsType childValue)
          Creates and inserts two Terms with specified values into Taxonomy and creates a relationship between them.
 boolean setRelship(FacetsType parentValue, int parentId, FacetsType childValue, int childId)
          Create the terms and sets the relationship parent - child between the two Terms.
 int setRelship(int parentId, FacetsType childValue)
          Set a relationship between two terms.
 boolean setRelship(Term<FacetsType> parent, Term<FacetsType> child)
          Sets relationship parent - child between two Terms.
 boolean setRelshipsMaterialization(Materialization toDo)
          Materializes or cancels relationships if Terms are comparable.
 void setTaxonomy(Taxonomy<?> tx)
          Clears the taxonomy and gives to the Taxonomy the properties of the argument.
 void setType(java.lang.String type)
          Defines the Java type of the Terms of the Taxonomy.
 void setValidation(Validation value)
          Sets the value of variable that defines if taxonomy is valid.
 java.lang.String toString()
          Returns a string representation of all materialized relationships.
 
Methods inherited from class fleXplorer.Terminologies.Terminology
containsTerm, containsTermWithId, decrSeqNumber, deleteAllIndexes, getComparability, getSeqNumber, getTerm, getTerm, getTerm, getTermId, getTerminology, getTermWithId, incrSeqNumber, isComparable, isEmpty, removeTerm, removeTerm, removeTerm, removeTermWithId, setComparability, setSeqNumber, setTerm, setTerm, setTerm, setTerminology, setTerms, setTermsValues, size
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Taxonomy

public Taxonomy(Taxonomy<Type> tx)
Constructs a Taxonomy object with the same properties as the argument.
Preconditions: The argument must not be null.
Postconditions: Constructs a Taxonomy object with the same properties as the argument.


Taxonomy

public Taxonomy()
Constructs a Taxonomy that doesn't checks the relationships of the Terms, the Terms are comparable, Taxonomy has an hierarchy and the Java type of terms are String. Preconditions: Always true Postconditions: Constructs a Taxonomy that doesn't checks the relationships of the Terms, the Terms are comparable, Taxonomy has an hierarchy and the Java type of terms are String.


Taxonomy

public Taxonomy(java.lang.String taxName)
Constructs a Taxonomy with specified name and doesn't checks the relationships of the Terms, the Terms are comparable, Taxonomy has an hierarchy and the Java type of terms are String..
Preconditions: Argument must not be null.
Postconditions: Constructs a Taxonomy with specified name and it doesn't checks the relationships of the Terms, the Terms are comparable, Taxonomy has an hierarchy and the Java type of terms are String.

Parameters:
taxName - the name of Taxonomy.

Taxonomy

public Taxonomy(java.lang.String name,
                CheckRel checkRel,
                Comparison comparability,
                HasLists hasLists,
                java.lang.String type)
Constructs a Taxonomy with the specified name, comparability and check of relationships and defines if the Taxonomy has hierarchy or it is flat.
Preconditions: Arguments must not be null.
Postconditions: Constructs a Taxonomy with specified name and defines if the terms of Taxonomy are comparable or not. Defines if the check of redundant relationships and relationships that cause cycles in graph will eliminate when defined a relationship. Also defines if Terms will have ids, if hasId is false must comparability be true. Also starts the sequence number for ids from zero.

Parameters:
taxName - the name of Taxonomy.
checkRel - the value of variable that defines when will be the check for cycles and redundant relationships.
comparability - the value of variable that defines if the Terms that included into Terminology of Taxonomy are comparable.
hasLists - the value of variable that defines if Terminology's Terms have lists for its parents and children.
type - the Java type of Terms's value of Taxonomy.
Method Detail

getType

public java.lang.String getType()
Returns the Java type of the Terms of the Taxonomy. Preconditions: Always true.
Postconditions: Returns the value of private variable type.

Specified by:
getType in interface ITaxonomy<Type extends FacetsType>
Returns:
the Java type of the Terms of the Taxonomy.

setType

public void setType(java.lang.String type)
Defines the Java type of the Terms of the Taxonomy. Preconditions: Argument must not be null, and valid java type.
Postconditions: Sets the value of private variable type.

Specified by:
setType in interface ITaxonomy<Type extends FacetsType>

setHasLists

public void setHasLists(HasLists value)
Sets the value of variable that defines if the taxonomy is flat or there is a hierarchy.
Preconditions: The argument must not be null.
Postconditions: Changes the value of private variable hasLists. If argument is false then, to be hasLists false must private variable comparability be true.

Specified by:
setHasLists in interface ITaxonomy<Type extends FacetsType>
Parameters:
value - the new value for private variable hasLists.

setTaxonomy

public void setTaxonomy(Taxonomy<?> tx)
Clears the taxonomy and gives to the Taxonomy the properties of the argument. Preconditions: The argument must not be null.
Postconditions: Clears the taxonomy and gives to the Taxonomy the properties of the argument.

Specified by:
setTaxonomy in interface ITaxonomy<Type extends FacetsType>
Parameters:
tx - the taxonomy that from which this Taxonomy will take the properties.

hasLists

public boolean hasLists()
Returns the value of variable that defines if Taxonomy's Terms have lists for its parents and children.
Preconditions: Always true.
Postconditions: Returns true if the value of private variable hasLists is TRUE.

Specified by:
hasLists in interface ITaxonomy<Type extends FacetsType>
Returns:
true if the taxonomy has hierarchy; false otherwise.

setName

public void setName(java.lang.String name)
Defines the name of Taxonomy.
Preconditions: Taxonomy's name must not be null.
Postconditions: Defines as value of private variable name the argument.

Specified by:
setName in interface ITaxonomy<Type extends FacetsType>
Specified by:
setName in interface ITerminology<Type extends FacetsType>
Overrides:
setName in class Terminology<Type extends FacetsType>
Parameters:
name - the new name of Taxonomy.

getName

public java.lang.String getName()
Returns the name of Taxonomy.
Preconditions: Always true.
Postconditions: Returns the value of private variable name.

Specified by:
getName in interface ITaxonomy<Type extends FacetsType>
Specified by:
getName in interface ITerminology<Type extends FacetsType>
Overrides:
getName in class Terminology<Type extends FacetsType>
Returns:
the name of Taxonomy.

checkRel

public boolean checkRel()
Return the value of variable that defines when will be the check for cycles and redundant relationships.
Preconditions: Always true.
Postconditions: Returns true if the value of private variable checkRel is TRUE.

Specified by:
checkRel in interface ITaxonomy<Type extends FacetsType>
Returns:
true if the taxonomy checks for cycles and redundant relationships; false otherwise.

setCheckRel

public void setCheckRel(CheckRel checkRel)
Sets the value of variable that defines when will be the check for cycles and redundant relationships.
Preconditions: The argument must not be null.
Postconditions: Changes the value of private variable checkRel.

Specified by:
setCheckRel in interface ITaxonomy<Type extends FacetsType>
Parameters:
check - the new value for check.

printDirectChildren

public void printDirectChildren(Term<Type> parent)
Prints the direct children of the specified term. Preconditions: The argument must not be null and the Taxonomy must not be flat.
Postconditions: Prints the direct children of the specified term. It finds the direct parents of term from parents list.

Specified by:
printDirectChildren in interface ITaxonomy<Type extends FacetsType>
Parameters:
term - the parent term

printDirectParents

public void printDirectParents(Term<Type> child)
Prints the direct parents of the specified term. Preconditions: The argument must not be null and the Taxonomy must not be flat.
Postconditions: Prints the direct parents of the specified term. It finds the direct children of term from parents list.

Specified by:
printDirectParents in interface ITaxonomy<Type extends FacetsType>
Parameters:
term - the child term

setValidation

public void setValidation(Validation value)
Sets the value of variable that defines if taxonomy is valid.
Preconditions: The argument must not be null.
Postconditions: Changes the value of private variable validation.

Specified by:
setValidation in interface ITaxonomy<Type extends FacetsType>
Parameters:
value - the new value for validation.

getValidation

public Validation getValidation()
Returns if taxonomy is valid. Preconditions: Always true.
Postconditions: Returns the value of private variable validation.

Specified by:
getValidation in interface ITaxonomy<Type extends FacetsType>
Returns:
Validation.TRUE if Taxonomy is valid.

removeDirectChild

public boolean removeDirectChild(Term<FacetsType> parent,
                                 Term<FacetsType> child)
Removes the child Term of the specified parent Term with the specified value.
Preconditions: The arguments must not be null and the Taxonomy must not be flat.
Postconditions: Checks if parent Term has a child with the specified value. If yes removes it from the list of children and the opposite and returns true; false otherwise.

Specified by:
removeDirectChild in interface ITaxonomy<Type extends FacetsType>
Parameters:
parent - The Term that will be removed its child.
child - The child Term to be removed.
Returns:
true if child removed successfully; false otherwise.

removeDirectParent

public boolean removeDirectParent(Term<FacetsType> child,
                                  Term<FacetsType> parent)
Removes the parent Term of the specified child Term with the specified value.
Preconditions: The arguments must not be null and the Taxonomy must not be flat.
Postconditions: Checks if child term has a parent with the specified value. If yes removes it from the list of parents and returns true; false otherwise.

Specified by:
removeDirectParent in interface ITaxonomy<Type extends FacetsType>
Parameters:
child - The Term that will be removed its parent.
parent - The parent Term to be removed.
Returns:
true if parent removed successfully; false otherwise.

directChildrenSize

public int directChildrenSize(Term<FacetsType> parent)
Returns the number of the direct children of the specified term.
Preconditions: The argument must not be null and the Taxonomy must not be flat.
Postconditions: Returns the number of the direct children of the specified term. If list is null, returns zero.

Specified by:
directChildrenSize in interface ITaxonomy<Type extends FacetsType>
Parameters:
parent - The Term whose the size of children list will be returned.
Returns:
the number of children of the specified term.

containsChild

public boolean containsChild(int parentId,
                             FacetsType childValue)
Return true if the term with the specified id has a direct child with the specified value. Preconditions: The childValue must not be null, the Taxonomy must not be flat and the parentId must not be negative.
Postconditions: Return true if the list of children contains the specified pair.

Specified by:
containsChild in interface ITaxonomy<Type extends FacetsType>
Parameters:
parentId - the id of parent term
childValue - the value of child term
Returns:
true if the term with the specified id has a direct child with the specified value

containsChild

public boolean containsChild(int parentId,
                             int childId)
Return true if the term with the specified id has a direct child with the specified id. Preconditions: The Taxonomy must not be flat and the ids must not be negatives.
Postconditions: Return true if the list of children contains the specified pair.

Specified by:
containsChild in interface ITaxonomy<Type extends FacetsType>
Parameters:
parentId - the id of parent term.
childId - the id of child term.
Returns:
true if the term with the specified id has a direct child with the specified id.

containsParent

public boolean containsParent(int childId,
                              FacetsType parentValue)
Return true if the term with the specified id has a direct parent with the specified value. Preconditions: The Taxonomy must not be flat and the ids must not be negative.
Postconditions: Return true if the list of parents contains the specified pair.

Specified by:
containsParent in interface ITaxonomy<Type extends FacetsType>
Parameters:
childId - the id of child term
parentValue - the value of parent term
Returns:
true if the term with the specified id has a direct parent with the specified value

containsParent

public boolean containsParent(int childId,
                              int parentId)
Return true if the term with the specified id has a direct parent with the specified id. Preconditions: The Taxonomy must not be flat and the ids must not be negatives.
Postconditions: Return true if the list of parents contains the specified pair.

Specified by:
containsParent in interface ITaxonomy<Type extends FacetsType>
Parameters:
childId - the id of child term.
parentId - the id of parent term.
Returns:
true if the term with the specified id has a direct parent with the specified id.

directParentsSize

public int directParentsSize(Term<FacetsType> child)
Returns the number of the direct parents of the specified Term.
Preconditions: Argument must not be null. The Taxonomy must not be flat.
Postconditions: Returns the size of argument's list of parents. If list is null, returns zero.

Specified by:
directParentsSize in interface ITaxonomy<Type extends FacetsType>
Parameters:
term - The Term whose the number of parents will be returned.
Returns:
the number of parents of the specified Term.

directParentsSize

public int directParentsSize(int childId)
Returns the number of the direct parents of the Term with the specified id.
Preconditions: The child id must not be negative. The Taxonomy must not be flat.
Postconditions: Returns the size of argument's list of parents. If list is null, returns zero.

Specified by:
directParentsSize in interface ITaxonomy<Type extends FacetsType>
Parameters:
childId - The id of Term whose the number of parents will be returned.
Returns:
the number of parents of the Term with the specified id.

directChildrenSize

public int directChildrenSize(int parentId)
Returns the number of the direct children of the Term with the specified id.
Preconditions: The parent id must not be negative. The Taxonomy must not be flat.
Postconditions: Returns the size of argument's list of children. If list is null, returns zero.

Specified by:
directChildrenSize in interface ITaxonomy<Type extends FacetsType>
Parameters:
childId - The id of Term whose the number of children will be returned.
Returns:
the number of children of the Term with the specified id.

getNumOfRelations

public int getNumOfRelations()
Returns the number of relations of the taxonomy. Preconditions: Always true.
Postconditions: Calculate the number of relations of the taxonomy and returns the number.

Specified by:
getNumOfRelations in interface ITaxonomy<Type extends FacetsType>
Returns:
the number of relations of the taxonomy.

getAllRelations

public java.util.Map<Term<FacetsType>,java.util.Collection<Term<FacetsType>>> getAllRelations()
Returns a Map with all relationships of the taxonomy. Preconditions: The Taxonomy must not be flat.
Postconditions: Returns the parents map.

Specified by:
getAllRelations in interface ITaxonomy<Type extends FacetsType>
Returns:
a Map with all relationships of the taxonomy.

getTermId

public int getTermId(java.lang.String path)
Returns the id of the term that described by the specified id. The terms are picked out through underscore.

Parameters:
path -
Returns:

getDirectChildren

public java.util.Collection<Term<FacetsType>> getDirectChildren(Term<FacetsType> parent)
Returns the direct children of the specified Term.
Preconditions: The Taxonomy must not be flat. Argument must not be null.
Postconditions: Returns a Collection that contains the direct children of Term.

Specified by:
getDirectChildren in interface ITaxonomy<Type extends FacetsType>
Parameters:
parent - The Term whose the direct children Terms will be returned.
Returns:
the list that contains the direct children of the specified term.

getDirectChildren

public java.util.Collection<Term<FacetsType>> getDirectChildren(int parentId)
Returns the direct children of the Term with the specified id.
Preconditions: The Taxonomy must not be flat. Argument must not be null.
Postconditions: Returns a Collection that contains the direct children of Term.

Specified by:
getDirectChildren in interface ITaxonomy<Type extends FacetsType>
Parameters:
parentId - The id of Term whose the direct children Terms will be returned.
Returns:
the list that contains the direct children of the Term with the specified id.

getDirectParents

public java.util.Collection<Term<FacetsType>> getDirectParents(Term<FacetsType> child)
Returns the direct parents of the specified Term.
Preconditions: The Taxonomy must not be flat. Argument must not be null.
Postconditions: Returns a Collection that contains the direct parents of Term.

Specified by:
getDirectParents in interface ITaxonomy<Type extends FacetsType>
Parameters:
child - The Term whose the direct parents Terms will be returned.
Returns:
the list that contains the direct parents of the specified term.

getDirectParents

public java.util.Collection<Term<FacetsType>> getDirectParents(int childId)
Returns the direct parents of the Term with the specified id.
Preconditions: The Taxonomy must not be flat. The childId must not be negative.
Postconditions: Returns a Collection that contains the direct parents of Term.

Specified by:
getDirectParents in interface ITaxonomy<Type extends FacetsType>
Parameters:
childId - The id of Term whose the direct parents Terms will be returned.
Returns:
the list that contains the direct parents of the Term with the specified id.

isDirectChild

public boolean isDirectChild(Term<FacetsType> parent,
                             Term<FacetsType> child)
Checks if the second argument is direct child of the first one.
Preconditions: The Taxonomy must not be flat. Arguments must not be null.
Postconditions: Checks if first argument is included in children's list of second one. If yes returns true; false otherwise.

Specified by:
isDirectChild in interface ITaxonomy<Type extends FacetsType>
Parameters:
term - The Term that will be checked if second argument is one of its direct children.
child - The Term that will be checked if it is direct child of first argument.
Returns:
true if the second argument is direct child of the first one; false otherwise.

isDirectParent

public boolean isDirectParent(Term<FacetsType> child,
                              Term<FacetsType> parent)
Checks if the second argument is direct parent of the first one.
Preconditions: The Taxonomy must not be flat. Arguments must not be null.
Postconditions: Checks if the first argument included in parents list of the second one. If yes returns true; false otherwise.

Specified by:
isDirectParent in interface ITaxonomy<Type extends FacetsType>
Parameters:
term - The Term that will be checked if second argument is one of its direct parents.
parent - The Term that will be checked if it is direct parent of first argument.
Returns:
true if the second argument is direct parent of the first one; false otherwise.

getHead

public Term<FacetsType> getHead()
Returns the head term of the taxonomy if taxonomy is not flat else returns the top element. Preconditions: Always true.
Postconditions: If taxonomy is flat returns the top element else return the direct children of the top element. If top element has more than one children then returns null.

Specified by:
getHead in interface ITaxonomy<Type extends FacetsType>
Returns:
the head term of the taxonomy if taxonomy is not flat else returns the top element.

getTopElementId

public int getTopElementId()
Returns the id of the top element. Preconditions: Always true.
Postconditions: Returns zero, because when we create new Taxonomy we create the top element and give it the id 0.

Specified by:
getTopElementId in interface ITaxonomy<Type extends FacetsType>
Returns:
the id of the top element.

isZP

public boolean isZP(int termId,
                    java.util.HashSet<java.lang.Integer> indexes)
Returns true if the term with the specified id is a legal term according the list of documents(objects) that have to be presented(indexes). This method usually used in the case we have disable the counter information. Preconditions: The Taxonomy must not be flat. The id must not be negative and the indexes must not be null.
Postconditions: Returns true if this term or at least one term of its descendants have a legal id.

Specified by:
isZP in interface ITaxonomy<Type extends FacetsType>
Parameters:
termId - The id of the Term.
indexes - a HashSet with the ids of documents that have to be displayed.
Returns:
true if the term with the specified id is a legal term according the list of documents(objects) that have to be presented(indexes); false otherwise.

getCount

public int getCount(int termId,
                    java.util.HashSet<java.lang.Integer> indexes)
Returns the count information of the Term with the specified id according to the indexes. Preconditions: The Taxonomy must not be flat. The id must not be negative and the indexes must not be null.
Postconditions: Returns the intersection of the indexes the term and all its descendants with the specified indexes.

Specified by:
getCount in interface ITaxonomy<Type extends FacetsType>
Parameters:
termId - The id of the Term.
indexes - a HashSet with the ids of documents that have to be displayed.
Returns:
the count information of the Term with the specified id according to the indexes.

getCount

public int getCount(Term<FacetsType> term,
                    java.util.HashSet<java.lang.Integer> indexes)
Returns the count information of the specified Term according to the indexes. Preconditions: The Taxonomy must not be flat. The arguments must not be null.
Postconditions: Returns the intersection of the indexes the term and all its descendants with the specified indexes.

Specified by:
getCount in interface ITaxonomy<Type extends FacetsType>
Parameters:
term - The Term.
indexes - a HashSet with the ids of documents that have to be displayed.
Returns:
the count information of the specified Term according to the indexes.

getCount

public java.util.HashMap<Term<FacetsType>,java.lang.Integer> getCount(java.util.HashSet<java.lang.Integer> indexes)
Returns the count information for all Terms of the flat Taxonomy according to the indexes. Preconditions: The Taxonomy must be flat. The argument must not be null.
Postconditions: For each term of terminology check if it is a legal zoom-in point

Specified by:
getCount in interface ITaxonomy<Type extends FacetsType>
Parameters:
indexes - a HashSet with the ids of documents that have to be displayed.
Returns:
the count information for all Terms of the flat Taxonomy according to the indexes.

getAllIds

public java.util.HashSet<java.lang.Integer> getAllIds(int termId)
Returns all ids of the documents that is indexed to the term with the specified id and all its descendants. Preconditions: The id must not be negative.
Postconditions: Adds to a hashset all ids of the indexed documents of each descendant term of the term with the specified id.

Specified by:
getAllIds in interface ITaxonomy<Type extends FacetsType>
Parameters:
indexes - a HashSet with the ids of documents that have to be displayed.
Returns:
all ids of the documents that is indexed to the term with the specified id and all its descendants.

getAllIds

public java.util.HashSet<java.lang.Integer> getAllIds(Term<FacetsType> term)
Returns all ids of the documents that is indexed to the specified term and all its descendants. Preconditions: The term must not be null.
Postconditions: Adds to a hashset all ids of the indexed documents of each descendant term of the specified term.

Specified by:
getAllIds in interface ITaxonomy<Type extends FacetsType>
Parameters:
indexes - a HashSet with the ids of documents that have to be displayed.
Returns:
all ids of the documents that is indexed to the specified term and all its descendants.

getAllChildren

public java.util.ArrayList<Term<FacetsType>> getAllChildren(Term<FacetsType> parent)
Returns all children of the specified term.
Preconditions: The Taxonomy must be flat. The argument must not be null.
Postconditions: Starts from the direct children of the term and get all descendants of the term

Specified by:
getAllChildren in interface ITaxonomy<Type extends FacetsType>
Parameters:
parent - Term of which list of children will be returned.
Returns:
a Collection that contains all children of the specified Term.

removeAllTheOtherIndexes

public void removeAllTheOtherIndexes(int termId)
If the taxonomy is not flat, removes the indexes of all terms of the taxonomy except the indexes of the term with the specified id and all of its descendants. In case it is flat, removes the all the indexes except the indexes of the term with the specified id. Preconditions: The id must not be negative.
Postconditions: If the taxonomy is not flat, removes the indexes of all terms of the taxonomy except the indexes of the term with the specified id and all of its descendants. In case it is flat, removes the all the indexes except the indexes of the term with the specified id.

Specified by:
removeAllTheOtherIndexes in interface ITaxonomy<Type extends FacetsType>
Parameters:
termId - the id of the term

removeRelship

public boolean removeRelship(int parentId,
                             int childId)
Removes the relationship between two terms. It doesn't removes the terms from the terminology. Preconditions: The ids must not be negative, the taxonomy must not be flat and the one term must be direct child or direct parent of the other.
Postconditions: Removes from the list of children of the parent term the child term and the opposite.

Specified by:
removeRelship in interface ITaxonomy<Type extends FacetsType>
Parameters:
parentId - the id of the parent term
childId - the id of the child term
Returns:
true if the relationship is removed successfully; false otherwise.

removeRelship

public boolean removeRelship(Term<FacetsType> parent,
                             Term<FacetsType> child)
Removes the relationship between two terms. It doesn't removes the terms from the terminology. Preconditions: The terms must not be null, the taxonomy must not be flat and the one term must be direct child or direct parent of the other.
Postconditions: Removes from the list of children of the parent term the child term and the opposite.

Specified by:
removeRelship in interface ITaxonomy<Type extends FacetsType>
Parameters:
parent - the parent term of the relationship.
child - the child term of the re
Returns:
true if the relationship is removed successfully; false otherwise.

getAllParents

public java.util.ArrayList<Term<FacetsType>> getAllParents(Term<FacetsType> child)
Returns all parents of the specified term.
Preconditions: The Taxonomy must not be flat. The argument must not be null.
Postconditions: Starts from the direct parents of the term and get all ancestors of the term.

Specified by:
getAllParents in interface ITaxonomy<Type extends FacetsType>
Parameters:
child - Term of which list of parents will be returned.
Returns:
a Collection that contains all parents of the specified Term.

getAllParentsWithHierarchy

public java.util.HashMap<java.lang.Integer,java.util.Collection<Term<FacetsType>>> getAllParentsWithHierarchy(Term<FacetsType> child)
Returns a HashMap with all parents of the specified term using hierarchy. The HasMap includes the pairs (depth, parents). The key of this HashMap is an Integer that specifies level in hierarchy of the a parent. Preconditions: The Taxonomy must not be flat and the argument must not be null.
Postconditions: Starts from the direct parents of the term and add them to the hasmap giving the depth using an integer.

Specified by:
getAllParentsWithHierarchy in interface ITaxonomy<Type extends FacetsType>
Parameters:
child - the child term
Returns:
a HashMap with all parents of the specified term using hierarchy.

getTermPath

public java.lang.String getTermPath(int tid)
Returns the path of the term with the specific id.

Parameters:
tid - the id of the term.
Returns:
the path of the term.

getAllParents

public java.util.Collection<Term<FacetsType>> getAllParents(int childId)
Returns all parents of the specified term.
Preconditions: The Taxonomy must not be flat and the id must not be negative.
Postconditions: Returns all parents of the specified terms. Starts from the direct parents and goes to all ancestors.

Specified by:
getAllParents in interface ITaxonomy<Type extends FacetsType>
Parameters:
term - The Term of which list of parents will be returned.
Returns:
an Collection that contains all parents of the specified Term.

isChild

public boolean isChild(Term<FacetsType> parent,
                       Term<FacetsType> child)
Checks if the second argument is a child of the first one.
Preconditions: The Taxonomy must not be flat and the terms must not be null.
Postconditions: Checks if first argument included in children list of second one. If yes returns true; false otherwise.

Specified by:
isChild in interface ITaxonomy<Type extends FacetsType>
Parameters:
parent - The Term that will be checked if second argument is one of its children.
child - The Term that will be checked if it is child of the first term.
Returns:
true if the second argument is a child of the first one; false otherwise.

isParent

public boolean isParent(Term<FacetsType> child,
                        Term<FacetsType> parent)
Checks if the second term is a parent of the first one.
Preconditions: The Taxonomy must not be flat and the terms must not be null.
Postconditions: Checks if the first argument included in the parents list of the second one. If yes returns true; false otherwise.

Specified by:
isParent in interface ITaxonomy<Type extends FacetsType>
Parameters:
child - The Term that will be checked if the second argument is one of its parents.
parent - The Term that will be checked if it is parent of the first argument.
Returns:
true if the second argument is a parent of the first one; false otherwise.

setRelship

public boolean setRelship(Term<FacetsType> parent,
                          Term<FacetsType> child)
Sets relationship parent - child between two Terms.
Preconditions: The Taxonomy must not be flat and the terms must not be null.
Postconditions: Sets a relationship parent - child between arguments. If variable checkRel is true, calls the isValidRel(parent, child) method to check the relationship, if it is false sets the relationship with out checking. And it adds the terms to the terminology.

Specified by:
setRelship in interface ITaxonomy<Type extends FacetsType>
Parameters:
parent - the parent Term of the relationship.
child - the child Term of the relationship.
Returns:
true if the relationship is implemented successfully; false otherwise;

setRelship

public boolean setRelship(FacetsType parentValue,
                          int parentId,
                          FacetsType childValue,
                          int childId)
Create the terms and sets the relationship parent - child between the two Terms.
Preconditions: The Taxonomy must not be flat and the values must not be null and the ids must not be negatives.
Postconditions: Sets a relationship parent - child between arguments. If variable checkRel is true, calls the isValidRel(parent, child) method to check the relationship, if it is false sets the relationship with out checking. And it adds the terms to the terminology.

Specified by:
setRelship in interface ITaxonomy<Type extends FacetsType>
Parameters:
parentValue - the value of the parent term
parentId - the id of the parent term
childValue - the value of the child term
childId - the id of the child term
Returns:
true if the relationship is set successfully; false otherwise.

setRelship

public java.util.HashMap<java.lang.String,java.lang.Integer> setRelship(FacetsType parentValue,
                                                                        FacetsType childValue)
Creates and inserts two Terms with specified values into Taxonomy and creates a relationship between them.
Preconditions: The arguments must not be null and the taxonomy must not be flat. Postconditions: Constructs two Terms checks if already included in Taxonomy, if not adds them. Then, if variable checkRel is true, it checks if relationship is redundant or causes a cycle, if it is false sets the relationship with out checking.

Specified by:
setRelship in interface ITaxonomy<Type extends FacetsType>
Parameters:
parentValue - the value of parent Term.
childValue - the value of child Term.
Returns:
the ids of the child and parent terms.

setRelship

public int setRelship(int parentId,
                      FacetsType childValue)
Set a relationship between two terms. The parent must already exists into the taxonomy and adds the child value to the parent. Finally, returns the id of the child term. Preconditions: The parent must be already in the taxonomy. The Taxonomy must not be flat and the childValue must not be null and the parentid must not be negatives.
Postconditions: Sets a relationship parent - child between arguments. If variable checkRel is true, calls the isValidRel(parent, child) method to check the relationship, if it is false sets the relationship with out checking. And it adds the terms to the terminology.

Specified by:
setRelship in interface ITaxonomy<Type extends FacetsType>
Parameters:
parentId - the id of the parent term
childValue - the value of the child term
Returns:
the id of the child term if the relationship added successfully; -1 otherwise.

getChildId

public int getChildId(int parentId,
                      FacetsType childValue)
Returns the id of the child term with the specified value of the parent term with the specified id. If there is no such relationship it returns -1. Preconditions: The Taxonomy must not be flat and the childValue must not be null and the parentId must not be negatives.
Postconditions: Checks preconditions, gets the direct children of the parent term, and iterates until it finds the child with the specified value. When finds it, returns it's id. If there is no such relationship it returns -1.

Specified by:
getChildId in interface ITaxonomy<Type extends FacetsType>
Parameters:
parentId - the id of the parent term
childValue - the value of the child term
Returns:
the id of the child term.

isRR

public boolean isRR(Term<FacetsType> parent,
                    Term<FacetsType> child)
Checks if this relationship parent - child is redundant.
Preconditions: Taxonomy must not be flat and the arguments must not be null. Postconditions: Checks if this relationship parent - child is redundant. If checking of relationships has been defined as true then when this method called it will check if this relationship is redundant. To check if this relationship is redundant it just checks if the child term is included in the list of the descendants of the parent term. If yes returns true; false otherwise.

Specified by:
isRR in interface ITaxonomy<Type extends FacetsType>
Parameters:
parent - parent Term of relationship.
child - child Term of relationship.
Returns:
true if relationship is redundant.

isCycle

public boolean isCycle(Term<FacetsType> parent,
                       Term<FacetsType> child)
Checks if this relationship parent - child causes a cycle to Taxonomy's graph. Preconditions: Taxonomy must not be flat and the arguments must not be null.
Postconditions: Checks if the parent term has already a parent which is the child term of this method. If there is no parents or children of a term, so the relationship can not causes a cycle.

Specified by:
isCycle in interface ITaxonomy<Type extends FacetsType>
Parameters:
parent - parent Term of relationship.
child - child Term of relationship.
Returns:
true if relationship causes a cycle to Taxonomy's graph; false otherwise.

toString

public java.lang.String toString()
Returns a string representation of all materialized relationships.
Preconditions: Always true.
Postconditions: Returns a string representation of all materialized relationships.

Specified by:
toString in interface ITaxonomy<Type extends FacetsType>
Specified by:
toString in interface ITerminology<Type extends FacetsType>
Overrides:
toString in class Terminology<Type extends FacetsType>
Returns:
a string representation of all materialized relationships.

clear

public void clear()
Removes all relationships and terms from the taxonomy. Preconditions: Always true.
Postconditions: Clears the children list, the parents list and the terminology.

Specified by:
clear in interface ITaxonomy<Type extends FacetsType>
Specified by:
clear in interface ITerminology<Type extends FacetsType>
Overrides:
clear in class Terminology<Type extends FacetsType>

addHead

public int addHead(FacetsType head)
Add a head term at the taxonomy. Preconditions: The argument must not be null and the taxonomy must not be flat.
Postconditions: Adds to the list of the children of the top element the id of the term, and the opposite.

Specified by:
addHead in interface ITaxonomy<Type extends FacetsType>
Parameters:
head - the value of the
Returns:
the id of the head.

getTopElement

public Term<FacetsType> getTopElement()
Returns the top element. Preconditions: Always true.
Postconditions: Returns the top element

Specified by:
getTopElement in interface ITaxonomy<Type extends FacetsType>
Returns:
the top element.

isValid

public boolean isValid()
Search for cycles in Taxonomy. If detects a cycle returns true and defines Taxonomy as invalid. Preconditions: Taxonomy must not be null. The variable for checking of relationships must be false.
Postconditions: Search for cycles in Taxonomy. If detect a cycle returns true and define Taxonomy as invalid.

Specified by:
isValid in interface ITaxonomy<Type extends FacetsType>
Returns:
true if it doesn't detects a cycle in Taxonomy; false otherwise.

elimRR

public void elimRR()
Eliminates redundant relationships.
Preconditions: Taxonomy must not be flat.
Postconditions: Checks Taxonomy from redundant relationships and eliminates them.

Specified by:
elimRR in interface ITaxonomy<Type extends FacetsType>

setRelshipsMaterialization

public boolean setRelshipsMaterialization(Materialization toDo)
Materializes or cancels relationships if Terms are comparable.
Preconditions: Taxonomy must not be null. Private variable comparability must be true.
Postconditions: If enumeration type is MATERIALIZE then materializes the relationships. If its CANCEL cancels all relationships between Taxonomy's Terms.

Specified by:
setRelshipsMaterialization in interface ITaxonomy<Type extends FacetsType>
Returns:
true if relationships are materialized or canceled successfully; false otherwise;

isBroader

public boolean isBroader(int parentId,
                         int childId)
Checks if a term is broader that an other (subsumption checking).

Parameters:
parentId - the id of the parent term.
childId - the id of the child term.
Returns:
true if parent term is correctly parent of the child term; false otherwise.

isNarrower

public boolean isNarrower(int parentId,
                          int childId)
Checks if a term is broader that an other (subsumption checking).

Parameters:
parentId - the id of the parent term.
childId - the id of the child term.
Returns:
true if parent term is correctly parent of the child term; false otherwise.