Skip to content

Commit

Permalink
修复可变DAT的entrySet方法 fix #1038
Browse files Browse the repository at this point in the history
  • Loading branch information
hankcs committed Dec 8, 2018
1 parent 54a230b commit 43f0ea8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.hankcs.hanlp.corpus.io.ICacheAble;

import java.io.*;
import java.util.ArrayList;

/**
* 动态数组
Expand Down Expand Up @@ -205,4 +206,15 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
exponentialExpanding = in.readBoolean();
exponentialExpandFactor = in.readDouble();
}

@Override
public String toString()
{
ArrayList<Integer> head = new ArrayList<Integer>(20);
for (int i = 0; i < Math.min(size, 20); ++i)
{
head.add(data[i]);
}
return head.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ public KeyValuePair()
from = b + i;
path.append(from);
b = base.get(from);
i = 0;
if (getCheck(b + UNUSED_CHAR_VALUE) == from)
{
value = getLeafValue(getBase(b + UNUSED_CHAR_VALUE));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
package com.hankcs.hanlp.model.perceptron.feature;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.collection.trie.datrie.MutableDoubleArrayTrieInteger;
import com.hankcs.hanlp.model.perceptron.model.LinearModel;
import junit.framework.TestCase;

import java.util.Map;
import java.util.TreeMap;

public class ImmutableFeatureMDatMapTest extends TestCase
{
public void testCompress() throws Exception
{
LinearModel model = new LinearModel(HanLP.Config.PerceptronCWSModelPath);
model.compress(0.1);
}

public void testFeatureMap() throws Exception
{
LinearModel model = new LinearModel(HanLP.Config.PerceptronCWSModelPath);
ImmutableFeatureMDatMap featureMap = (ImmutableFeatureMDatMap) model.featureMap;
MutableDoubleArrayTrieInteger dat = featureMap.dat;
System.out.println(featureMap.size());
System.out.println(featureMap.entrySet().size());
System.out.println(featureMap.idOf("\u0001/\u00014"));
TreeMap<String, Integer> map = new TreeMap<String, Integer>();
for (Map.Entry<String, Integer> entry : dat.entrySet())
{
map.put(entry.getKey(), entry.getValue());
assertEquals(entry.getValue().intValue(), dat.get(entry.getKey()));
}
System.out.println(map.size());
assertEquals(dat.size(), map.size());
}
}

0 comments on commit 43f0ea8

Please sign in to comment.