本文整理匯總了Java中org.ardverk.collection.PatriciaTrie類的典型用法代碼示例。如果您正苦於以下問題:Java PatriciaTrie類的具體用法?Java PatriciaTrie怎麽用?Java PatriciaTrie使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PatriciaTrie類屬於org.ardverk.collection包,在下文中一共展示了PatriciaTrie類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: plus
import org.ardverk.collection.PatriciaTrie; //導入依賴的package包/類
public synchronized void plus(PatriciaTrie<String, Integer> another) {
for (Entry<String, Integer> e: another.entrySet()){
Integer score = get(e.getKey());
score = score == null ? e.getValue() : e.getValue() + score;
put(e.getKey(), score);
}
}
示例2: minus
import org.ardverk.collection.PatriciaTrie; //導入依賴的package包/類
public synchronized void minus(PatriciaTrie<String, Integer> another){
for (Entry<String, Integer> e: another.entrySet()){
Integer score = get(e.getKey());
score = score == null ? - e.getValue() : score - e.getValue();
put(e.getKey(), score);
}
}
示例3: Dictionary
import org.ardverk.collection.PatriciaTrie; //導入依賴的package包/類
public Dictionary(boolean loadDefault){
trie = new PatriciaTrie<String, Double>(StringKeyAnalyzer.CHAR);
if(loadDefault)
loadDicFile(DEFAULT_DIC_NAME);
}
示例4: StringSparseVector
import org.ardverk.collection.PatriciaTrie; //導入依賴的package包/類
public StringSparseVector(Parameters params) {
this.params = params;
this.vector = new PatriciaTrie<String, Double>(StringKeyAnalyzer.CHAR);
}
示例5: main
import org.ardverk.collection.PatriciaTrie; //導入依賴的package包/類
public static void main(String args[]) throws IOException{
PerceptronClassifier weight = new PerceptronClassifier();
FeatureSet featSet = new FeatureSet();
featSet.put("好雨知時節");
featSet.put("當春乃發生");
featSet.put("隨風潛入夜");
featSet.put("潤物細無聲");
featSet.put("潤物細無聲");
LogInfo.logs(featSet);
LogInfo.logs(weight);
LogInfo.logs(weight.score(featSet));
weight.plus(featSet);
LogInfo.logs(weight);
LogInfo.logs(weight.score(featSet));
weight.put("潤物細無聲", 1);
LogInfo.logs(weight);
LogInfo.logs(weight.score(featSet));
PatriciaTrie<String, Integer> feat = new PatriciaTrie<String, Integer>(StringKeyAnalyzer.CHAR);
feat.put("抽煙", 1);
feat.put("抽煙", 1);
feat.put("喝酒", 1);
feat.put("燙頭", 1);
PerceptronClassifier feat2 = new PerceptronClassifier();
feat2.put("洗衣", 1);
feat2.put("做飯", 1);
PatriciaTrie<String, Integer> feat3 = new PatriciaTrie<String, Integer>(StringKeyAnalyzer.CHAR);
feat3.put("做飯", 1);
feat3.put("抽煙", 1);
feat3.put("燙頭", 1);
feat3.put("路癡", 1);
// PerceptronClassifier feat4 = feat2.clone();
// feat2.clear();
// System.out.println("+++" + feat4);
//
System.out.println("none:" + weight.score(feat2));
weight.plus(feat2);
System.out.println("after pending 2 score 1: " + weight.score(feat));
System.out.println("after pending 2 score 2: " + weight.score(feat2));
System.out.println("after pending 2 score 3: " + weight.score(feat3));
weight.minus(feat);
System.out.println("after substracting 1 score 3: " + weight.score(feat3));
weight.plus(feat3);
System.out.println(weight);
weight.rebuild();
System.out.println(weight);
PipedOutputStream os = new PipedOutputStream();
PipedInputStream pi = new PipedInputStream(os);
PrintWriter pw = new PrintWriter(os);
weight.dump(pw);
pw.println();
pw.println("hahaha"); //test
pw.close();
BufferedReader bt =new BufferedReader(new InputStreamReader(pi));
PerceptronClassifier another = new PerceptronClassifier();
another.load(bt);
bt.close();
System.out.println(another);
os.close();
pi.close();
}
示例6: loadMarkup
import org.ardverk.collection.PatriciaTrie; //導入依賴的package包/類
public static void loadMarkup(BufferedReader br) throws IOException{
List<String> plainCache = new ArrayList<String>();
List<String> indexedCache = new ArrayList<String>();
String s = br.readLine();
int state = 0;
String plainCat = null;
String indexedCat = null;
int line = 0;
while (s != null){
if (s.equals("EOP")) break;
line++;
s = s.trim();
if (s.length() == 0){
if (state == 1)
LogInfo.warning("Wrong Format at line" + line);
else if(state > 0){
plainCache.add(plainCat);
indexedCache.add(indexedCat);
}
state = 0;
}else{
s = s.replaceAll("#.*$", "").trim();
if (s.length() != 0){
switch(state){
case 0:
plainCat = s;
state = 1;
break;
case 1:
indexedCat = s;
state = 2;
break;
case 2:
if (s.charAt(0) == '!'){
char c = indexedCat.charAt(0);
s.replace('!', c);
break;
}
case 3:
state = 3;
//TODO GR;
}
}
}
s = br.readLine();
}
if (state == 1) // when gr is done, state==2 is also not illegal
LogInfo.warning("Incomplete File");
else if(state > 0){
plainCache.add(plainCat);
indexedCache.add(indexedCat);
}
PatriciaTrie<String, String> _cache = new PatriciaTrie<String, String>(StringKeyAnalyzer.CHAR);
for (int i = 0; i< plainCache.size(); ++i){
String pcat = plainCache.get(i);
_cache.put(pcat.replace('(', '{').replace(')', '}'), indexedCache.get(i));
}
CCGTerminalNode.setInterpret(_cache);
}
示例7: setInterpret
import org.ardverk.collection.PatriciaTrie; //導入依賴的package包/類
public static void setInterpret(PatriciaTrie<String, String> interpretation){
_interpretation = interpretation;
}