修改自然语言BUG

pull/1/head
lidapeng 5 years ago
parent 4b77887601
commit 97c5dcd3a8

@ -44,10 +44,9 @@ public class Talk {
List<String> keyWords = sentence1.getKeyWords(); List<String> keyWords = sentence1.getKeyWords();
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
int nub = 0; int nub = 0;
List<String> words = wordTimes.get(i); if (keyWords.size() > i) {
String word = keyWords.get(i); List<String> words = wordTimes.get(i);
if (word != null) { nub = getNub(words, keyWords.get(i));
nub = getNub(words, word);
} }
features.add(nub); features.add(nub);
} }

@ -42,12 +42,13 @@ public class Tokenizer extends Frequency {
} }
private void number() {//分词编号 private void number() {//分词编号
System.out.println("开始编码:" + sentences.size());
for (Sentence sentence : sentences) { for (Sentence sentence : sentences) {
List<Integer> features = sentence.getFeatures(); List<Integer> features = sentence.getFeatures();
List<String> sentenceList = sentence.getKeyWords(); List<String> sentenceList = sentence.getKeyWords();
int size = sentenceList.size();//时间序列的深度 int size = sentenceList.size();//时间序列的深度
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
if (!wordTimes.contains(i)) { if (wordTimes.size() < i + 1) {
wordTimes.add(new ArrayList<>()); wordTimes.add(new ArrayList<>());
} }
List<String> list = wordTimes.get(i); List<String> list = wordTimes.get(i);
@ -77,7 +78,7 @@ public class Tokenizer extends Frequency {
langBody.setKey(sentence.getKey()); langBody.setKey(sentence.getKey());
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
int nub = 0; int nub = 0;
if (features.contains(i)) { if (features.size() > i) {
nub = features.get(i); nub = features.get(i);
} }
int t = i + 1; int t = i + 1;

@ -2,4 +2,19 @@ package org.wlld.naturalLanguage;
public class WordConst { public class WordConst {
public static double Word_Noise = 0.7;//收缩程度 public static double Word_Noise = 0.7;//收缩程度
public static final int SHOP = 1;//购买类型
public static final int FOOD = 3;//食物类型
public static final int DRINK = 4;//饮品类型
public static final int OTHER = 5;//家庭日用(油盐酱醋卫生纸之类的)
public static final int SMOKE = 10;//烟草
public static final int ADD = 6;//订单增0.5037412492
public static final int DEL = 7;//订单删
public static final int UPDATE = 8;//订单改
public static final int SELECT = 9;//订单查
public static final int TALK = 2;//聊天类型
public static final int ALL = 11;//全文本
public static final int CHANGE = 12;//分类文本
public static final int DROP = 13;//消文本
public static final int CURD = 14;//对订单增删改查类型
public static final int ANS = 0;//聊天回复
} }

@ -81,6 +81,7 @@ public class RandomForest {
public void study() throws Exception {//学习 public void study() throws Exception {//学习
for (int i = 0; i < forest.length; i++) { for (int i = 0; i < forest.length; i++) {
System.out.println("开始学习==" + i + ",treeNub==" + forest.length);
Tree tree = forest[i]; Tree tree = forest[i];
tree.study(); tree.study();
} }

@ -16,8 +16,11 @@ public class LangTest {
public static void test() throws Exception { public static void test() throws Exception {
TemplateReader templateReader = new TemplateReader(); TemplateReader templateReader = new TemplateReader();
templateReader.read("/Users/lidapeng/Desktop/myDocment/a.txt", "UTF-8", IOConst.NOT_WIN); templateReader.read("/Users/lidapeng/Desktop/myDocment/a2.txt", "UTF-8", IOConst.NOT_WIN);
Talk talk = new Talk(); Talk talk = new Talk();
talk.talk("我要吃面包"); talk.talk("我要吃面包");
talk.talk("我渴了");
talk.talk("我要去看望你");
talk.talk("我买两盒烟");
} }
} }

Loading…
Cancel
Save