本文整理汇总了Java中cc.mallet.util.PropertyList类的典型用法代码示例。如果您正苦于以下问题:Java PropertyList类的具体用法?Java PropertyList怎么用?Java PropertyList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PropertyList类属于cc.mallet.util包,在下文中一共展示了PropertyList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pipe
import cc.mallet.util.PropertyList; //导入依赖的package包/类
public Instance pipe (Instance carrier)
{
TokenSequence ts = (TokenSequence) carrier.getData();
int tsSize = ts.size();
for (int i = tsSize-1; i >= 0; i--) {
Token t = ts.get (i);
String text = t.getText();
if (featureRegex != null && !featureRegex.matcher(text).matches())
continue;
for (int j = 0; j < i; j++) {
if (ts.get(j).getText().equals(text)) {
PropertyList.Iterator iter = ts.get(j).getFeatures().iterator();
while (iter.hasNext()) {
iter.next();
String key = iter.getKey();
if (filterRegex == null || (filterRegex.matcher(key).matches() ^ !includeFiltered))
t.setFeatureValue (namePrefix+key, iter.getNumericValue());
}
break;
}
if (firstMentionName != null)
t.setFeatureValue (firstMentionName, 1.0);
}
}
return carrier;
}
示例2: pipe
import cc.mallet.util.PropertyList; //导入依赖的package包/类
public Instance pipe(Instance carrier) {
AgglomerativeNeighbor neighbor = (AgglomerativeNeighbor) carrier
.getData();
Clustering original = neighbor.getOriginal();
int[] cluster1 = neighbor.getOldClusters()[0];
int[] cluster2 = neighbor.getOldClusters()[1];
InstanceList list = original.getInstances();
int[] mergedIndices = neighbor.getNewCluster();
Record[] records = array2Records(mergedIndices, list);
Alphabet fieldAlph = records[0].fieldAlphabet();
Alphabet valueAlph = records[0].valueAlphabet();
PropertyList features = null;
features = addExactMatch(records, fieldAlph, valueAlph, features);
features = addApproxMatch(records, fieldAlph, valueAlph, features);
features = addSubstringMatch(records, fieldAlph, valueAlph, features);
carrier
.setData(new FeatureVector(getDataAlphabet(), features,
true));
LabelAlphabet ldict = (LabelAlphabet) getTargetAlphabet();
String label = (original.getLabel(cluster1[0]) == original
.getLabel(cluster2[0])) ? "YES" : "NO";
carrier.setTarget(ldict.lookupLabel(label));
return carrier;
}
示例3: readObject
import cc.mallet.util.PropertyList; //导入依赖的package包/类
private void readObject (ObjectInputStream in) throws IOException, ClassNotFoundException {
int version = in.readInt ();
data = in.readObject();
target = in.readObject();
name = in.readObject();
source = in.readObject();
properties = (PropertyList) in.readObject();
locked = in.readBoolean();
}
示例4: AugmentableFeatureVector
import cc.mallet.util.PropertyList; //导入依赖的package包/类
public AugmentableFeatureVector (Alphabet dict, PropertyList pl, boolean binary,
boolean growAlphabet) {
this (dict, binary);
if (pl == null)
return;
PropertyList.Iterator iter = pl.numericIterator();
while (iter.hasNext()) {
iter.nextProperty();
//System.out.println ("AugmentableVector ("+dict.size()+") adding "+iter.getKey()+" "+iter.getNumericValue());
int index = dict.lookupIndex (iter.getKey(), growAlphabet);
if (index >= 0)
add (index, iter.getNumericValue());
}
}
示例5: toStringWithFeatureNames
import cc.mallet.util.PropertyList; //导入依赖的package包/类
public String toStringWithFeatureNames () {
StringBuffer sb = new StringBuffer ();
sb.append (getText());
if (features != null) {
PropertyList.Iterator iter = features.iterator();
while (iter.hasNext()) {
iter.next();
sb.append (" " + iter.getKey());
}
}
return sb.toString();
}
示例6: initStartEndFs
import cc.mallet.util.PropertyList; //导入依赖的package包/类
private static void initStartEndFs ()
{
for (int i = 0; i < maxWindowSize; i++) {
startfs[i] = PropertyList.add ("<START"+i+">", 1.0, null);
endfs[i] = PropertyList.add ("<END"+i+">", 1.0, null);
}
}
示例7: makeConjunctions
import cc.mallet.util.PropertyList; //导入依赖的package包/类
/** Recursively makes conjunctions by iterating through features at each offset
* @param iters iterate over the PropertyLists at each offset
* @param currIndex which offset we're currently on, e..g 1 in the list [0,1,2]
* @param conjunctions list of conjunctions
* @param j which offset list we're currently on, e.g. [0,1,2] in the list [[0,1],[0,1,2]]
* @param tsSize size of token sequence
* @param newfs new features
* @param tsi token sequence index
* @param oldfs old features
* @param iterIndices counter to keep track how far in each iterator in "iters"
* @return new features
*/
private PropertyList makeConjunctions (PropertyList.Iterator[] iters, int currIndex, int[][] conjunctions,
int j, int tsSize, PropertyList newfs, int tsi, PropertyList[] oldfs,
int[] iterIndices) {
if (iters.length == currIndex) { // base case: add feature for current conjunction of iters
// avoid redundant doubling of feature space; include only upper triangle
if (redundant (conjunctions, j, iterIndices)) {
return newfs;
}
String newFeature = "";
double newValue = 1.0;
for (int i=0; i < iters.length; i++) {
String s = iters[i].getKey();
if (featureRegex != null && !featureRegex.matcher(s).matches())
return newfs;
newFeature += (i==0 ? "" : "_&_") + s + (conjunctions[j][i]==0 ? "" : ("@" + conjunctions[j][i]));
newValue *= iters[i].getNumericValue();
}
//System.err.println ("Adding new feature " + newFeature);
newfs = PropertyList.add (newFeature, newValue, newfs);
}
else { // recursive step
while (iters[currIndex].hasNext()) {
iters[currIndex].next();
iterIndices[currIndex]++;
newfs = makeConjunctions (iters, currIndex+1, conjunctions, j, tsSize, newfs, tsi, oldfs, iterIndices);
}
// reset iterator at currIndex
iters[currIndex] = getOffsetIter (conjunctions, j, currIndex, tsSize, tsi, oldfs);
iterIndices[currIndex] = -1;
}
return newfs;
}
示例8: getOffsetIters
import cc.mallet.util.PropertyList; //导入依赖的package包/类
/** Get iterators for each token in this offset */
private PropertyList.Iterator[] getOffsetIters (int [][] conjunctions, int j, int tsSize, int tsi,
PropertyList[] oldfs) {
PropertyList.Iterator[] iters = new PropertyList.Iterator[conjunctions[j].length];
// get iterators for offsets
for (int iteri=0; iteri < iters.length; iteri++) {
iters[iteri] = getOffsetIter (conjunctions, j, iteri, tsSize, tsi, oldfs);
if (iters[iteri]==null)
return null;
}
return iters;
}
示例9: getOffsetIter
import cc.mallet.util.PropertyList; //导入依赖的package包/类
private PropertyList.Iterator getOffsetIter (int [][] conjunctions, int j, int iteri, int tsSize, int tsi,
PropertyList[] oldfs) {
PropertyList.Iterator iter;
if (tsi+conjunctions[j][iteri] < 0)
iter = startfs[-(tsi+conjunctions[j][iteri])-1].iterator();
else if (conjunctions[j][iteri]+tsi > tsSize-1)
iter = endfs[tsi+conjunctions[j][iteri]-tsSize].iterator();
else if (oldfs[conjunctions[j][iteri]+tsi] == null)
iter = null;
else
iter = oldfs[tsi+conjunctions[j][iteri]].iterator();
return iter;
}
示例10: pipe
import cc.mallet.util.PropertyList; //导入依赖的package包/类
public Instance pipe (Instance carrier)
{
TokenSequence ts = (TokenSequence) carrier.getData();
int tsSize = ts.size();
PropertyList[] newFeatures = new PropertyList[tsSize];
for (int i = 0; i < tsSize; i++) {
Token t = ts.get (i);
PropertyList pl = t.getFeatures();
newFeatures[i] = pl;
for (int position = i + leftBoundary; position < i + rightBoundary; position++) {
if (position == i && !includeCurrentToken)
continue;
PropertyList pl2;
if (position < 0)
pl2 = startfs[-position];
else if (position >= tsSize)
pl2 = endfs[position-tsSize];
else
pl2 = ts.get(position).getFeatures ();
PropertyList.Iterator pl2i = pl2.iterator();
while (pl2i.hasNext()) {
pl2i.next();
String key = pl2i.getKey();
if (featureRegex == null || featureRegex.matcher(key).matches()) {
newFeatures[i] = PropertyList.add ((namePrefixLeft == null || position-i>0 ? namePrefix : namePrefixLeft)+key,
pl2i.getNumericValue(), newFeatures[i]);
}
}
}
}
for (int i = 0; i < tsSize; i++) {
// Put the new PropertyLists in place
ts.get (i).setFeatures (newFeatures[i]);
}
return carrier;
}
示例11: hasMatchingFeature
import cc.mallet.util.PropertyList; //导入依赖的package包/类
private boolean hasMatchingFeature (Token token, Pattern pattern)
{
PropertyList.Iterator iter = token.getFeatures ().iterator ();
while (iter.hasNext()) {
iter.next();
if (pattern.matcher (iter.getKey()). matches ()) {
if (iter.getNumericValue() == 1.0) {
return true;
}
}
}
return false;
}
示例12: addExactMatch
import cc.mallet.util.PropertyList; //导入依赖的package包/类
private PropertyList addExactMatch(Record[] records,
Alphabet fieldAlph, Alphabet valueAlph, PropertyList features) {
for (int fi = 0; fi < exactMatchFields.length; fi++) {
int matches = 0;
int comparisons = 0;
for (int i = 0; i < records.length
&& exactMatchFields.length > 0; i++) {
FeatureVector valsi = records[i]
.values(exactMatchFields[fi]);
for (int j = i + 1; j < records.length && valsi != null; j++) {
FeatureVector valsj = records[j]
.values(exactMatchFields[fi]);
if (valsj != null) {
comparisons++;
for (int ii = 0; ii < valsi.numLocations(); ii++) {
if (valsj.contains(valueAlph.lookupObject(valsi
.indexAtLocation(ii)))) {
matches++;
break;
}
}
}
}
if (matches == comparisons && comparisons > 1)
features = PropertyList.add(fieldAlph
.lookupObject(exactMatchFields[fi])
+ "_all_match", 1.0, features);
if (matches > 0)
features = PropertyList.add(fieldAlph
.lookupObject(exactMatchFields[fi])
+ "_exists_match", 1.0, features);
}
}
return features;
}
示例13: testOne
import cc.mallet.util.PropertyList; //导入依赖的package包/类
public void testOne ()
{
PropertyList pl = null;
pl = PropertyList.add ("one", 1.0, pl);
pl = PropertyList.add ("two", 2.0, pl);
pl = PropertyList.add ("three", 3, pl);
assertTrue (pl.lookupNumber("one") == 1.0);
pl = PropertyList.remove ("three", pl);
assertTrue (pl.lookupNumber("three") == 0.0);
pl = PropertyList.add ("color", "red", pl);
assertTrue (pl.lookupObject("color").equals("red"));
}
示例14: BigAugmentableFeatureVector
import cc.mallet.util.PropertyList; //导入依赖的package包/类
public BigAugmentableFeatureVector (BigAlphabet dict, PropertyList pl, boolean binary,
boolean growAlphabet) {
this (dict, binary);
if (pl == null)
return;
PropertyList.Iterator iter = pl.numericIterator();
while (iter.hasNext()) {
iter.nextProperty();
//System.out.println ("AugmentableVector ("+dict.size()+") adding "+iter.getKey()+" "+iter.getNumericValue());
int index = dict.lookupIndex (iter.getKey(), growAlphabet);
if (index >= 0)
add (index, iter.getNumericValue());
}
}
示例15: makeConjunctions
import cc.mallet.util.PropertyList; //导入依赖的package包/类
/**
* Recursively makes conjunctions by iterating through features at each
* offset
*
* @param iters
* iterate over the PropertyLists at each offset
* @param currIndex
* which offset we're currently on, e..g 1 in the list [0,1,2]
* @param conjunctions
* list of conjunctions
* @param j
* which offset list we're currently on, e.g. [0,1,2] in the list
* [[0,1],[0,1,2]]
* @param tsSize
* size of token sequence
* @param newfs
* new features
* @param tsi
* token sequence index
* @param oldfs
* old features
* @param iterIndices
* counter to keep track how far in each iterator in "iters"
* @return new features
*/
private PropertyList makeConjunctions(PropertyList.Iterator[] iters,
int currIndex, int[][] conjunctions, int j, int tsSize,
PropertyList newfs, int tsi, PropertyList[] oldfs, int[] iterIndices) {
if (iters.length == currIndex) { // base case: add feature for current
// conjunction of iters
// avoid redundant doubling of feature space; include only upper
// triangle
if (redundant(conjunctions, j, iterIndices)) {
return newfs;
}
String newFeature = "";
double newValue = 1.0;
for (int i = 0; i < iters.length; i++) {
String s = iters[i].getKey();
if (featureRegex != null && !featureRegex.matcher(s).matches())
return newfs;
newFeature += (i == 0 ? "" : "_&_")
+ s
+ (("@" + conjunctions[j][i]));
newValue *= iters[i].getNumericValue();
}
// System.err.println ("Adding new feature " + newFeature);
newfs = PropertyList.add(newFeature, newValue, newfs);
} else { // recursive step
while (iters[currIndex].hasNext()) {
iters[currIndex].next();
iterIndices[currIndex]++;
newfs = makeConjunctions(iters, currIndex + 1, conjunctions, j,
tsSize, newfs, tsi, oldfs, iterIndices);
}
// reset iterator at currIndex
iters[currIndex] = getOffsetIter(conjunctions, j, currIndex,
tsSize, tsi, oldfs);
iterIndices[currIndex] = -1;
}
return newfs;
}