diff --git a/src/main/java/org/dromara/easyai/entity/SentenceModel.java b/src/main/java/org/dromara/easyai/entity/SentenceModel.java new file mode 100644 index 0000000..192fd0a --- /dev/null +++ b/src/main/java/org/dromara/easyai/entity/SentenceModel.java @@ -0,0 +1,55 @@ +package org.dromara.easyai.entity; + +import java.util.*; + +/** + * @param + * @DATA + * @Author LiDaPeng + * @Description + */ +public class SentenceModel { + private final List sentenceList = new ArrayList<>();//每一句话 + private final Set wordSet = new HashSet<>(); + private final String splitWord;//词向量默认隔断符,无隔断则会逐字隔断 + + public SentenceModel(String splitWord) { + this.splitWord = splitWord; + } + + public SentenceModel() { + this.splitWord = null; + } + + public void setSentenceBySplitWord(String sentence) throws Exception { + if (splitWord != null && !splitWord.isEmpty()) { + String[] words = sentence.split(splitWord); + Collections.addAll(wordSet, words); + sentenceList.add(words); + } else { + throw new Exception("没有设置隔断符,无法使用基于隔断符的切割"); + } + } + + public void setSentence(String sentence) {//输入语句没有隔断符 + String[] words = new String[sentence.length()]; + for (int i = 0; i < sentence.length(); i++) { + String word = sentence.substring(i, i + 1); + words[i] = word; + wordSet.add(word); + } + sentenceList.add(words); + } + + public List getSentenceList() { + return sentenceList; + } + + public String getSplitWord() { + return splitWord; + } + + public Set getWordSet() { + return wordSet; + } +}