C
- the type of the conditionsV
- the type of the samplespublic class ConditionalFrequencyDistribution<C,V> extends Object
FrequencyDistribution
.
This class could be used to learn how frequently a word collocates with another word. Suppose we
want to know how frequently the word "of" appears after the word "because", then
ConditionalFrequencyDistribution
can be used as follows:
ConditionalFrequencyDistribution<String, String> cfd = new ConditionalFrequencyDistribution<String, String>(); cfd.addSample("because", "in"); cfd.addSample("because", "of"); cfd.addSample("despite", "in"); cfd.addSample("because", "of"); System.out.println(cfd.getCount("despite", "of"));
The last call to getCount(C, V)
will yield 2,
because given the condition
that the first word in a two-word sequence is "because",
the word "of" has appeared twice.
This class was inspired by NLTK's FreqDist.
FrequencyDistribution
Constructor and Description |
---|
ConditionalFrequencyDistribution()
Creates a new empty
ConditionalFrequencyDistribution . |
ConditionalFrequencyDistribution(Map<C,Iterable<V>> samples)
Creates a new
ConditionalFrequencyDistribution and fills it with samples from a map. |
Modifier and Type | Method and Description |
---|---|
void |
addSample(C condition,
V sample,
long frequency)
Adds a sample with a certain frequency under a given
condition . |
Set<C> |
getConditions()
Returns all conditions for which samples have been recorded.
|
long |
getCount(C condition,
V sample)
Returns the total number of samples which equal a given
sample under a given
condition . |
FrequencyDistribution<V> |
getFrequencyDistribution(C condition)
Returns the
FrequencyDistribution under a given condition , or
null if this distribution contains no such FrequencyDistribution for
this condition . |
long |
getN() |
boolean |
hasCondition(C condition)
Indicates whether samples have been recorded under a given
condition . |
void |
inc(C condition,
V sample)
Increases a sample under a given
condition . |
void |
incAll(C condition,
Iterable<V> samples)
Increases all provided samples under a given
condition . |
void |
removeCondition(C condition)
Remove a previously registered condition
|
void |
setFrequencyDistribution(C condition,
FrequencyDistribution<V> fd)
Directly set the frequency distribution for a given condition.
|
String |
toString() |
public ConditionalFrequencyDistribution()
ConditionalFrequencyDistribution
.public long getN()
public long getCount(C condition, V sample)
sample
under a given
condition
.
If there are no samples for the condition in question on record, 0
will be
returned.
condition
- the conditionsample
- the sample under a given conditionsample
public FrequencyDistribution<V> getFrequencyDistribution(C condition)
FrequencyDistribution
under a given condition
, or
null
if this distribution contains no such FrequencyDistribution
for
this condition
.condition
- the conditionpublic void setFrequencyDistribution(C condition, FrequencyDistribution<V> fd)
condition
- the condition.fd
- the distribution.public Set<C> getConditions()
Set
of all recorded conditionspublic boolean hasCondition(C condition)
condition
.condition
- the condition in questioncondition
existpublic void inc(C condition, V sample)
condition
.condition
- the condition for this samplesample
- the sample to addpublic void incAll(C condition, Iterable<V> samples)
condition
.
If there is no FrequencyDistribution
present for the given condition
, a
new empty one will be created and populated from the given samples
.
condition
- the condition for the samplessamples
- the samples to addpublic void addSample(C condition, V sample, long frequency)
condition
.condition
- the condition for this samplesample
- the sample to addfrequency
- the frequenc of the samplepublic void removeCondition(C condition)
condition
- the condition to be removedCopyright © 2007–2018 Ubiquitous Knowledge Processing (UKP) Lab, Technische Universität Darmstadt. All rights reserved.