Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GetWordsImplTest #772

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/test/java/org/ansj/app/phrase/PhraseExtractorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.ansj.app.phrase;

import org.junit.Assert;
import org.junit.Test;

import java.util.List;
import java.util.Map;

public class PhraseExtractorTest {

@Test
public void test1() {
PhraseExtractor phraseExtractor = new PhraseExtractor();
List<Map.Entry<String, Occurrence>> nbest = phraseExtractor.nbest(2);
Assert.assertTrue(nbest.size() == 0);
}
}
29 changes: 29 additions & 0 deletions src/test/java/org/ansj/app/summary/SummaryComputerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.ansj.app.summary;

import org.ansj.app.summary.pojo.Summary;
import org.junit.Assert;
import org.junit.Test;

public class SummaryComputerTest {
SummaryComputer summaryComputer = new SummaryComputer("a", "b");

@Test
public void test1() {
SummaryComputer summaryComputer1 = new SummaryComputer(1, "c", "d");
Assert.assertNotSame(summaryComputer, summaryComputer1);
}

@Test
public void test2() {
Summary summary = summaryComputer.toSummary();
System.out.println(summary.getSummary());
Assert.assertEquals(summary.getSummary(), "b");
}

@Test
public void test3() {
Summary summary1 = summaryComputer.toSummary("e");
System.out.println(summary1.getSummary());
Assert.assertEquals(summary1.getSummary(), "b");
}
}
29 changes: 29 additions & 0 deletions src/test/java/org/ansj/dic/impl/LearnToolTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.ansj.dic.impl;

import org.ansj.dic.LearnTool;
import org.ansj.domain.Nature;
import org.ansj.splitWord.analysis.NlpAnalysis;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;

public class LearnToolTest {

@Test
public void test() throws IOException {
// 构建一个新词学习的工具类。这个对象。保存了所有分词中出现的新词。出现次数越多。相对权重越大。
LearnTool learnTool = new LearnTool();

NlpAnalysis nlpAnalysis = new NlpAnalysis().setLearnTool(learnTool);

// 进行词语分词。也就是nlp方式分词,这里可以分多篇文章
nlpAnalysis.parseStr("说过,社交软件也是打着沟通的平台,让无数寂寞男女有了肉体与精神的寄托。");
nlpAnalysis.parseStr("其实可以打着这个需求点去运作的互联网公司不应只是社交类软件与可穿戴设备,还有携程网,去哪儿网等等,订房订酒店多好的寓意");
nlpAnalysis.parseStr("张艺谋的卡宴,马明哲的戏");

// 只取得词性为Nature.NR的新词
System.out.println(learnTool.getTopTree(10, Nature.NR));
Assert.assertEquals(learnTool.getTopTree(10, Nature.NR).toString(), "[]");
}
}
24 changes: 24 additions & 0 deletions src/test/java/org/ansj/domain/AnsjItemTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.ansj.domain;

import org.junit.Assert;
import org.junit.Test;


public class AnsjItemTest {

@Test
public void test1() {
AnsjItem ansjItem = new AnsjItem();
String[] split = {"a", "b"};
ansjItem.init(split);
System.out.println(ansjItem.param);
Assert.assertEquals(ansjItem.param, "b");
}

@Test
public void test2() {
AnsjItem ansjItem = new AnsjItem();
System.out.println(ansjItem.toText());
Assert.assertEquals(ansjItem.toText(), "0 null 65536 0 0 null");
}
}
16 changes: 16 additions & 0 deletions src/test/java/org/ansj/domain/KVTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.ansj.domain;

import org.junit.Assert;
import org.junit.Test;


public class KVTest {

@Test
public void test1() {
KV<String, String> kv = KV.with("a", "b");
kv.setK("a1");
System.out.println(kv.getK());
Assert.assertEquals(kv.getK(), "a1");
}
}
22 changes: 22 additions & 0 deletions src/test/java/org/ansj/splitWord/analysis/GetWordsImplTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.ansj.splitWord.analysis;

import org.ansj.splitWord.impl.GetWordsImpl;
import org.junit.Assert;
import org.junit.Test;

public class GetWordsImplTest {
@Test
public void test() {
GetWordsImpl getWordsImpl = new GetWordsImpl("a");
System.out.println(getWordsImpl.chars);
Assert.assertArrayEquals(getWordsImpl.chars, new char[]{'a'});
}

@Test
public void test1() {
GetWordsImpl getWordsImpl = new GetWordsImpl();
System.out.println(getWordsImpl.getOffe());
Assert.assertEquals(getWordsImpl.getOffe(), 0);
}
}