public class CoOccurrenceMatrix extends java.util.AbstractMap<CoOccurrence,CoOccurrence> implements java.util.Map<CoOccurrence,CoOccurrence>
Dictionary and a collection of documents. The matrix is represented
as a HashMap where all CoOccurrence objects found
so far in the collection are stored.
Associated with a CoOccurrenceMatrix is also an index. For each Term present in the matrix, the index contains an ArrayList of all co-occurrence where the term takes part. The index is synchronized with the matrix. Adding/removing a CoOccurrence to/from the matrix will result in an updated index.
The co-occurrence matrix can also be seen as a graph where terms in the matrix represent the nodes and the co-occurrences represent the edges. The index can be considered to be an Adjacency list (wiki-link) , Nina Tahmasebi, L3S Research Center
| Modifier and Type | Class and Description |
|---|---|
class |
CoOccurrenceMatrix.CoOccComparatorFrq
A comparator for CoOccurrence so that they can be sorted on their
frequencies.
|
| Constructor and Description |
|---|
CoOccurrenceMatrix(Dictionary dictionary)
Constructs an empty CoOccurrenceMatrix where the dictionary is
set and the index is empty.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
compareIndex(java.util.HashMap<Term,java.util.ArrayList<CoOccurrence>> index) |
void |
createXMLFile(java.lang.String pathToXMLFile) |
java.util.ArrayList<java.lang.Integer> |
degreeDistribution()
Returns the degree distribution of this matrix.
|
java.util.Set |
entrySet()
Returns the entry set of this matrix.
|
boolean |
equals(java.lang.Object ma)
Compares two matrices.
|
CoOccurrenceMatrix |
extractLimitedPartOfMatrix(int degree,
int limit,
java.util.ArrayList<java.lang.String> seed) |
CoOccurrenceMatrix |
extractPartOfMatrix(int degree,
java.util.ArrayList<java.lang.String> seed)
Starting from a seed set extractPartOfMatrix iteratively extracts a
sub-matrix.
|
Dictionary |
getDictionary()
Returns the dictionary used for building this matrix
|
java.util.HashMap<Term,java.util.ArrayList<CoOccurrence>> |
getIndex()
Returns index representing the incidence matrix.
|
java.lang.String |
getPeriod() |
java.util.ArrayList<java.lang.String> |
getTopTerms(int k,
java.lang.String query)
Method for returning the top k terms that co-occur with
query term in the co-occurrence matrix.
|
java.util.Iterator<CoOccurrence> |
iterator()
Returns an iterator over all edges in the graph represented by
the matrix.
|
java.util.Iterator<Term> |
iteratorTerms()
Returns an iterator over all nodes in the graph represented by the matrix.
|
CoOccurrenceMatrix |
mergeMatrix(CoOccurrenceMatrix inputMatrix)
Merges this matrix with inputMatrix and removes the duplicates.
|
void |
normalizeMatrix() |
CoOccurrence |
put(CoOccurrence e,
CoOccurrence d)
The parameters e and d should be the same.
|
void |
remove(CoOccurrence co) |
boolean |
removeCoOccur(CoOccurrence co,
boolean removeLeaf) |
void |
removeLeafNodes()
Removes all leaf nodes from this matrix, i.e.
|
void |
removeLowFrequencyOccur(double i)
Removes all CoOccurrence with a co-occurrence frequency less
than or equal to i.
|
void |
setDictionary(Dictionary dictionary)
Changes dictionary for this matrix.
|
void |
setIndex(java.util.HashMap<Term,java.util.ArrayList<CoOccurrence>> index) |
void |
setPeriod(java.lang.String period) |
int |
size()
Returns the number of elements in this matrix
|
java.util.List<CoOccurrence> |
sort()
Method for sorting Matrix.
|
static java.util.List<CoOccurrence> |
sortCoOccrCollection(java.util.Collection<CoOccurrence> keySet,
java.util.Comparator<CoOccurrence> comp)
Method for sorting a a Collection of CoOccurrence.
|
void |
updateMatrix(CoOccurrence co)
Increases the frequency for the co-occurrence co by one.
|
void |
writeMatrixForClustering(double i,
java.io.Writer writer)
Output of the file is adapted to Beate Dorow's Clustering Algorithm.
|
void |
writeMatrixForSynonyms(double i,
java.io.Writer writer)
Output of the file is adapted to Beate Dorow's Clustering Algorithm.
|
void |
writeMatrixToFile(double i,
java.io.Writer writer)
Writes all occurrences of matrix that is larger that i to
writer.
|
public CoOccurrenceMatrix(Dictionary dictionary)
dictionary - the dictionary associated with the matrixpublic void clear()
clear in interface java.util.Map<CoOccurrence,CoOccurrence>clear in class java.util.AbstractMap<CoOccurrence,CoOccurrence>public boolean compareIndex(java.util.HashMap<Term,java.util.ArrayList<CoOccurrence>> index)
public java.util.Set entrySet()
entrySet in interface java.util.Map<CoOccurrence,CoOccurrence>entrySet in class java.util.AbstractMap<CoOccurrence,CoOccurrence>public void setPeriod(java.lang.String period)
public java.lang.String getPeriod()
public void remove(CoOccurrence co)
public boolean equals(java.lang.Object ma)
equals in interface java.util.Map<CoOccurrence,CoOccurrence>equals in class java.util.AbstractMap<CoOccurrence,CoOccurrence>public CoOccurrenceMatrix extractPartOfMatrix(int degree, java.util.ArrayList<java.lang.String> seed)
degree - determines the maximum distance that any CoOccurrence
in the resulting sub-matrix will have from the nodes in seedseed - is a list of starting nodes in the matrixpublic CoOccurrenceMatrix extractLimitedPartOfMatrix(int degree, int limit, java.util.ArrayList<java.lang.String> seed)
public java.util.ArrayList<java.lang.Integer> degreeDistribution()
public Dictionary getDictionary()
public java.util.HashMap<Term,java.util.ArrayList<CoOccurrence>> getIndex()
public java.util.Iterator<CoOccurrence> iterator()
public java.util.Iterator<Term> iteratorTerms()
public CoOccurrence put(CoOccurrence e, CoOccurrence d)
put in interface java.util.Map<CoOccurrence,CoOccurrence>put in class java.util.AbstractMap<CoOccurrence,CoOccurrence>public boolean removeCoOccur(CoOccurrence co, boolean removeLeaf)
public void removeLeafNodes()
a a
/ \ => / \
b - c - d - e b - c public void removeLowFrequencyOccur(double i)
i - the minimum number of occurrences that the elements in the
remaining matrix must havepublic void setDictionary(Dictionary dictionary)
dictionary - the dictionary to use
hpublic int size()
size in interface java.util.Map<CoOccurrence,CoOccurrence>size in class java.util.AbstractMap<CoOccurrence,CoOccurrence>public void updateMatrix(CoOccurrence co)
co - the co-occurrence to updatepublic void writeMatrixForClustering(double i,
java.io.Writer writer)
i - the threshold to be usedwriter - specifies where the output should be writtenpublic static java.util.List<CoOccurrence> sortCoOccrCollection(java.util.Collection<CoOccurrence> keySet, java.util.Comparator<CoOccurrence> comp)
Unit. The
comparator could specify sorting units based on number of internal
clusters, or longest spanning units etc. Note that the units need not to
be unique!keySet - Set of CoOccurrence to be sorted.comp - Comparator to be used for sorting CoOccurrence.public java.util.ArrayList<java.lang.String> getTopTerms(int k,
java.lang.String query)
k - - the top number of terms to returnquery - - the query term with which the top terms should co-occurpublic java.util.List<CoOccurrence> sort()
public void writeMatrixForSynonyms(double i,
java.io.Writer writer)
i - the threshold to be usedwriter - specifies where the output should be writtenpublic void writeMatrixToFile(double i,
java.io.Writer writer)
i - the threshold to be usedwriter - specifies where the output should be writtenpublic void normalizeMatrix()
public CoOccurrenceMatrix mergeMatrix(CoOccurrenceMatrix inputMatrix) throws java.lang.CloneNotSupportedException
inputMatrix - the matrix which should be mergedjava.lang.CloneNotSupportedExceptionpublic void createXMLFile(java.lang.String pathToXMLFile)
throws java.io.IOException
java.io.IOExceptionpublic void setIndex(java.util.HashMap<Term,java.util.ArrayList<CoOccurrence>> index)