Skip to content
Snippets Groups Projects
Verified Commit f644a6e7 authored by 家乐 袁's avatar 家乐 袁
Browse files

update:backend

parent f02e78b0
No related branches found
No related tags found
No related merge requests found
Showing
with 1117 additions and 22 deletions
File added
File deleted
......@@ -22,7 +22,7 @@
<artifactId>sentistrength_backend</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/sentistrength-1.0.0-SNAPSHOT.jar</systemPath>
<systemPath>${project.basedir}/lib/sentiStrength-v1.0.13.jar</systemPath>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -7,19 +7,61 @@ import org.springframework.stereotype.Repository;
@Repository
@Mapper
public interface UserDao {
/**
* 用户注册
*
* @param userPO 用户信息PO
*/
void register(UserPO userPO);
/**
* 根据用户名查找用户
*
* @param username 用户名
* @return 用户信息PO
*/
UserPO findByUserName(String username);
/**
* 根据用户邮箱查找用户
*
* @param email 用户邮箱
* @return 用户信息PO
*/
UserPO findByEmail(String email);
/**
* 根据用户电话号码查找用户
*
* @param phone 用户电话号码
* @return 用户信息PO
*/
UserPO findByPhone(String phone);
/**
* 用户登录(用户名方式)
*
* @param username 用户名
* @param password 密码
* @return 用户信息PO
*/
UserPO loginByUserName(String username, String password);
/**
* 用户登录(邮箱方式)
*
* @param email 用户邮箱
* @param password 密码
* @return 用户信息PO
*/
UserPO loginByEmail(String email, String password);
/**
* 用户登录(电话号码方式)
*
* @param phone 电话号码
* @param password 密码
* @return 用户信息PO
*/
UserPO loginByPhone(String phone, String password);
}
package com.sentistrength.enums;
import com.fasterxml.jackson.annotation.JsonValue;
public interface BaseEnum<E extends Enum<?>, T> {
/**
* 获取枚举的值
*
* @return 枚举的值
*/
@JsonValue
T getValue();
}
\ No newline at end of file
package com.sentistrength.enums;
public enum ClassificationMode implements BaseEnum<ClassificationMode, String>{
SCALE("scale"),
BINARY("binary"),
TRINARY("trinary");
/**
* 类成员变量 value String类型<br/>
* 枚举的值
*/
private final String value;
/**
* 构造方法,以字符串作为枚举的值进行构造
*
* @param value 枚举的值
*/
ClassificationMode(String value) {
this.value = value;
}
/**
* 获取枚举的值
*
* @return 枚举的值
*/
@Override
public String getValue() {
return null;
}
}
......@@ -10,13 +10,27 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@Builder
public class UserPO {
/**
* 类成员变量 username String类型<br/>
* 用户名
*/
private String username;
/**
* 类成员变量 password String类型<br/>
* 密码
*/
private String password;
/**
* 类成员变量 email String类型<br/>
* 用户邮箱
*/
private String email;
/**
* 类成员变量 phone String类型<br/>
* 用户电话号码
*/
private String phone;
}
package com.sentistrength.model.vo.sentistrength;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class InputFileVO {
/**
* 类成员变量 column int类型<br/>
* 分析的文本所在列号
*/
private int column;
/**
* 类成员变量 input String类型List<br/>
* 输入文件中的若干行文本
*/
private List<String> input;
}
package com.sentistrength.model.vo.sentistrength;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class MachineLearningVO {
/**
* 类成员变量 input String类型List<br/>
* 输入文件中的若干行文本
*/
private List<String> input;
/**
* 类成员变量 testAll boolean类型<br/>
* 是否测试所有算法配置选项
*/
private boolean testAll;
/**
* 类成员变量 minImprovement int类型<br/>
* 保留情绪权重优化的最小正确分类增加数
*/
private int minImprovement;
/**
* 类成员变量 useTotalDifference boolean类型<br/>
* 是否根据有差异的分类数量之和来进行优化(若否,则根据正确分类数量进行优化)
*/
private boolean useTotalDifference;
/**
* 类成员变量 iteration int类型<br/>
* 迭代次数
*/
private int iteration;
/**
* 类成员变量 multiOptimization int类型<br/>
* 进行优化的次数(最终的优化结果取平均值)
*/
private int multiOptimization;
}
package com.sentistrength.model.vo.sentistrength;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class OptionsVO {
// 算法逻辑设置
/**
* 类成员变量 classificationMode String类型<br/>
* 分类模式(default、scale、trinary、binary)
*/
private String classificationMode;
/**
* 类成员变量 emotionParagraphCombineMethod int类型<br/>
* 计算段落情感得分时采用所有句子的:最大值(0)、平均值(1)、总和(2),默认0
*/
private int emotionParagraphCombineMethod;
/**
* 类成员变量 emotionSentenceCombineMethod int类型<br/>
* 计算句子情感得分时采用所有术语的:最大值(0)、平均值(1)、总和(2),默认0
*/
private int emotionSentenceCombineMethod;
/**
* 类成员变量 allowMultiplePositiveWordsToIncreasePositiveEmotion boolean类型<br/>
* 是否允许积极单词叠加积极情感分数,默认true
*/
private boolean allowMultiplePositiveWordsToIncreasePositiveEmotion;
/**
* 类成员变量 allowMultipleNegativeWordsToIncreaseNegativeEmotion boolean类型<br/>
* 是否允许消极单词叠加消极情感分数,默认true
*/
private boolean allowMultipleNegativeWordsToIncreaseNegativeEmotion;
/**
* 类成员变量 multipleLettersBoostSentiment boolean类型<br/>
* 是否可以通过重复字母来增强情感,默认true
*/
private boolean multipleLettersBoostSentiment;
/**
* 类成员变量 minRepeatedLettersForBoost int类型<br/>
* 最少重复多少次才能增强情感,默认2
*/
private int minRepeatedLettersForBoost;
/**
* 类成员变量 boosterWordsChangeEmotion boolean类型<br/>
* 是否可以通过程度副词增强情感,默认true
*/
private boolean boosterWordsChangeEmotion;
/**
* 类成员变量 capitalsBoostTermSentiment boolean类型<br/>
* 是否单词全部大写可以增强感情,默认false
*/
private boolean capitalsBoostTermSentiment;
/**
* 类成员变量 negativeSentimentMultiplier float类型<br/>
* 消极情感分数加倍,默认1.5
*/
private float negativeSentimentMultiplier;
/**
* 类成员变量 reduceNegativeEmotionInQuestionSentences boolean类型<br/>
* 问句中的消极单词情感分数减少,默认false
*/
private boolean reduceNegativeEmotionInQuestionSentences;
// 算法考量范围
/**
* 类成员变量 useIdiomLookupTable boolean类型<br/>
* 是否将习语纳入情感分析,默认true
*/
private boolean useIdiomLookupTable;
/**
* 类成员变量 useObjectEvaluationTable boolean类型<br/>
* 是否将对象评价表纳入情感分析,默认false
*/
private boolean useObjectEvaluationTable;
/**
* 类成员变量 useEmoticons boolean类型<br/>
* 是否将表情纳入情感分析,默认true
*/
private boolean useEmoticons;
// 与否定词相关设置
/**
* 类成员变量 negatingWordsOccurBeforeSentiment boolean类型<br/>
* 是否否定词可以否定后续单词的情感,默认true
*/
private boolean negatingWordsOccurBeforeSentiment;
/**
* 类成员变量 maxWordsBeforeSentimentToNegate int类型<br/>
* 否定词否定后续单词的范围,默认0
*/
private int maxWordsBeforeSentimentToNegate;
/**
* 类成员变量 negatingWordsOccurAfterSentiment boolean类型<br/>
* 是否否定词可以否定之前单词的情感,默认false
*/
private boolean negatingWordsOccurAfterSentiment;
/**
* 类成员变量 maxWordsAfterSentimentToNegate int类型<br/>
* 否定词否定之前单词的范围,默认0
*/
private int maxWordsAfterSentimentToNegate;
/**
* 类成员变量 negatingWordsFlipEmotion boolean类型<br/>
* 是否否定词直接反转情感,默认false
*/
private boolean negatingWordsFlipEmotion;
/**
* 类成员变量 negatingPositiveFlipsEmotion boolean类型<br/>
* 是否否定词可以反转积极情感,默认true
*/
private boolean negatingPositiveFlipsEmotion;
/**
* 类成员变量 negatingNegativeNeutralisesEmotion boolean类型<br/>
* 是否否定词可以将消极情感变为中性,默认true
*/
private boolean negatingNegativeNeutralisesEmotion;
/**
* 类成员变量 strengthMultiplierForNegatedWords float类型<br/>
* 否定词反转情感时的分数乘数,默认0.5
*/
private float strengthMultiplierForNegatedWords;
/**
* 类成员变量 ignoreBoosterWordsAfterNegatives boolean类型<br/>
* 是否忽略否定词后的程度副词,默认true
*/
private boolean ignoreBoosterWordsAfterNegatives;
// 与强调相关设置
/**
* 类成员变量 minPunctuationWithExclamationToChangeSentenceSentiment int类型<br/>
* 当带有感叹号的标点符号强调部分长度超过该值时会增强感情,默认0
*/
private int minPunctuationWithExclamationToChangeSentenceSentiment;
/**
* 类成员变量 moodToInterpretNeutralEmphasis int类型<br/>
* 将原本中性的强调部分视作:积极(1)、中性(0)、消极(-1),默认1
*/
private int moodToInterpretNeutralEmphasis;
// 与讽刺相关设置
/**
* 类成员变量 minSentencePosForQuotesIrony int类型<br/>
* 当含有引用的句子积极情感分数超过该值时,视为反语讽刺,默认10
*/
private int minSentencePosForQuotesIrony;
/**
* 类成员变量 minSentencePosForPunctuationIrony int类型<br/>
* 当含有感叹号的句子积极情感分数超过该值时,视为反语讽刺,视为反语讽刺,默认10
*/
private int minSentencePosForPunctuationIrony;
/**
* 类成员变量 minSentencePosForTermsIrony int类型<br/>
* 当含有讽刺词的句子积极情感分数超过该值时,视为反语讽刺,默认10
*/
private int minSentencePosForTermsIrony;
// 自动纠正拼写
/**
* 类成员变量 correctSpellingsUsingDictionary boolean类型<br/>
* 是否自动纠正拼写错误,默认true
*/
private boolean correctSpellingsUsingDictionary;
/**
* 类成员变量 correctExtraLetterSpellingErrors boolean类型<br/>
* 是否自动根据以下字母表去除单词中不应重复的字母,默认true
*/
private boolean correctExtraLetterSpellingErrors;
/**
* 类成员变量 illegalDoubleLettersInWordMiddle String类型<br/>
* 不应在单词中间重复的字母表,默认ahijkquvxyz
*/
private String illegalDoubleLettersInWordMiddle;
/**
* 类成员变量 illegalDoubleLettersAtWordEnd String类型<br/>
* 不应在单词末尾重复的字母表,默认achijkmnpqruvwxyz
*/
private String illegalDoubleLettersAtWordEnd;
// 特殊情况
/**
* 类成员变量 missCountsAsPlus2 boolean类型<br/>
* 是否出现单词miss的非积极句子视作+2分,默认true
*/
private boolean missCountsAsPlus2;
/**
* 类成员变量 youOrYourIsPlus2UnlessSentenceNegative boolean类型<br/>
* 是否出现单词you或your或whats的非消极句子视作+2分,默认false
*/
private boolean youOrYourIsPlus2UnlessSentenceNegative;
/**
* 类成员变量 exclamationInNeutralSentenceCountsAsPlus2 boolean类型<br/>
* 是否出现感叹号的中性句子视作+2分,默认false
*/
private boolean exclamationInNeutralSentenceCountsAsPlus2;
// 其他
/**
* 类成员变量 explainClassification boolean类型<br/>
* 是否需要提供情感分析的过程解释,默认false
*/
private boolean explainClassification;
/**
* 类成员变量 forceUTF8 boolean类型<br/>
* 是否采用UTF-8格式,默认false
*/
private boolean forceUTF8;
/**
* 类成员变量 alwaysSplitWordsAtApostrophes boolean类型<br/>
* 是否总是允许撇号( ' )分割单词,默认false
*/
private boolean alwaysSplitWordsAtApostrophes;
/**
* 类成员变量 useLemmatisation boolean类型<br/>
* 是否采用词形归并还原,默认false
*/
private boolean useLemmatisation;
}
package com.sentistrength.model.vo.sentistrength;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ResourcesVO {
/**
* 类成员变量 type String类型<br/>
* 资源类型(boosterWordsList,emoticonsList,idiomList,ironyList,negatingWordsList,questionWordsList,sentimentWordsList,correctWordsList)
*/
private String type;
/**
* 类成员变量 list String类型List<br/>
* 若干行算法资源列表
*/
private List<String> list;
}
......@@ -10,13 +10,27 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@Builder
public class UserVO {
/**
* 类成员变量 username String类型<br/>
* 用户名
*/
private String username;
/**
* 类成员变量 password String类型<br/>
* 密码
*/
private String password;
/**
* 类成员变量 email String类型<br/>
* 用户邮箱
*/
private String email;
/**
* 类成员变量 phone String类型<br/>
* 用户电话号码
*/
private String phone;
}
\ No newline at end of file
package com.sentistrength.service.Impl.sentistrength;
import com.sentistrength.exception.MyServiceException;
import com.sentistrength.model.vo.sentistrength.InputFileVO;
import com.sentistrength.model.vo.sentistrength.MachineLearningVO;
import com.sentistrength.model.vo.sentistrength.OptionsVO;
import com.sentistrength.model.vo.sentistrength.ResourcesVO;
import com.sentistrength.service.Interface.sentistrength.SentiStrengthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.ac.wlv.sentistrength.ClassificationOptions;
import uk.ac.wlv.sentistrength.SentiStrength;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
@Service
public class SentiStrengthServiceImpl implements SentiStrengthService {
private final SentiStrength sentiStrength;
@Autowired
public SentiStrengthServiceImpl() throws RuntimeException {
sentiStrength = new SentiStrength();
if (!sentiStrength.simpleInitialise()) {
throw new RuntimeException("initialisation of SentiStrength failed");
}
}
/**
* 对文本进行情感分析
*
* @param text 待分析的文本
* @return String 分析的结果
*/
@Override
public String classifyText(String text) {
// 对URL型文本编码进行解析
try {
text = URLDecoder.decode(text, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new MyServiceException("SS001", "文本URL编码解析失败!");
}
String ans = sentiStrength.parseText(text);
// 重新编码为URL型文本
try {
System.out.println(URLEncoder.encode(ans, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new MyServiceException("SS002", "文本URL编码失败!");
}
return ans;
}
/**
* 对文件中的各行文本进行情感分析
*
* @param inputFileVO 用户输入文件VO
* @return List<String> 分析的结果列表
*/
@Override
public List<String> classifyFile(InputFileVO inputFileVO) {
List<String> ans = new ArrayList<>();
for (String line : inputFileVO.getInput()) {
if (!"".equals(line)) {
String[] tmp = line.split("\t");
if (tmp.length > inputFileVO.getColumn()) {
ans.add(classifyText(tmp[inputFileVO.getColumn()]));
} else {
throw new MyServiceException("SS003", "文本所在列标识有误!");
}
} else {
throw new MyServiceException("SS004", "文件存在空行!");
}
}
return ans;
}
/**
* 对文件夹中的所有文件进行情感分析
*
* @param inputFileVOList 用户输入文件VO列表
* @return List<List < String>> 各文件的分析结果列表
*/
@Override
public List<List<String>> classifyFiles(List<InputFileVO> inputFileVOList) {
List<List<String>> ans = new ArrayList<>();
for (InputFileVO inputFileVO : inputFileVOList) {
List<String> tmp = classifyFile(inputFileVO);
ans.add(tmp);
}
return ans;
}
/**
* 设置算法配置选项
*
* @param optionsVO 算法配置选项VO
*/
@Override
public void setOptions(OptionsVO optionsVO) {
ClassificationOptions classificationOptions = new ClassificationOptions();
boolean refreshFlag = classificationOptions.bgForceUTF8 != optionsVO.isForceUTF8()
|| classificationOptions.bgUseLemmatisation != optionsVO.isUseLemmatisation()
|| classificationOptions.bgCorrectSpellingsUsingDictionary != optionsVO.isCorrectSpellingsUsingDictionary();
// 算法逻辑设置
switch (optionsVO.getClassificationMode()) {
case "scale":
classificationOptions.bgScaleMode = true;
break;
case "trinary":
classificationOptions.bgTrinaryMode = true;
break;
case "binary":
classificationOptions.bgBinaryVersionOfTrinaryMode = true;
classificationOptions.bgTrinaryMode = true;
break;
case "default":
break;
default:
throw new MyServiceException("SS005", "此分类模式不存在!");
}
classificationOptions.igEmotionParagraphCombineMethod = optionsVO.getEmotionParagraphCombineMethod();
classificationOptions.igEmotionSentenceCombineMethod = optionsVO.getEmotionSentenceCombineMethod();
classificationOptions.bgAllowMultiplePositiveWordsToIncreasePositiveEmotion = optionsVO.isAllowMultiplePositiveWordsToIncreasePositiveEmotion();
classificationOptions.bgAllowMultipleNegativeWordsToIncreaseNegativeEmotion = optionsVO.isAllowMultipleNegativeWordsToIncreaseNegativeEmotion();
classificationOptions.bgMultipleLettersBoostSentiment = optionsVO.isMultipleLettersBoostSentiment();
classificationOptions.igMinRepeatedLettersForBoost = optionsVO.getMinRepeatedLettersForBoost();
classificationOptions.bgBoosterWordsChangeEmotion = optionsVO.isBoosterWordsChangeEmotion();
classificationOptions.bgCapitalsBoostTermSentiment = optionsVO.isCapitalsBoostTermSentiment();
classificationOptions.fgNegativeSentimentMultiplier = optionsVO.getNegativeSentimentMultiplier();
classificationOptions.bgReduceNegativeEmotionInQuestionSentences = optionsVO.isReduceNegativeEmotionInQuestionSentences();
// 算法考量范围
classificationOptions.bgUseIdiomLookupTable = optionsVO.isUseIdiomLookupTable();
classificationOptions.bgUseObjectEvaluationTable = optionsVO.isUseObjectEvaluationTable();
classificationOptions.bgUseEmoticons = optionsVO.isUseEmoticons();
// 与否定词相关设置
classificationOptions.bgNegatingWordsOccurBeforeSentiment = optionsVO.isNegatingWordsOccurBeforeSentiment();
classificationOptions.igMaxWordsBeforeSentimentToNegate = optionsVO.getMaxWordsBeforeSentimentToNegate();
classificationOptions.bgNegatingWordsOccurAfterSentiment = optionsVO.isNegatingWordsOccurAfterSentiment();
classificationOptions.igMaxWordsAfterSentimentToNegate = optionsVO.getMaxWordsAfterSentimentToNegate();
classificationOptions.bgNegatingWordsFlipEmotion = optionsVO.isNegatingWordsFlipEmotion();
classificationOptions.bgNegatingPositiveFlipsEmotion = optionsVO.isNegatingPositiveFlipsEmotion();
classificationOptions.bgNegatingNegativeNeutralisesEmotion = optionsVO.isNegatingNegativeNeutralisesEmotion();
classificationOptions.fgStrengthMultiplierForNegatedWords = optionsVO.getStrengthMultiplierForNegatedWords();
classificationOptions.bgIgnoreBoosterWordsAfterNegatives = optionsVO.isIgnoreBoosterWordsAfterNegatives();
// 与强调相关设置
classificationOptions.igMinPunctuationWithExclamationToChangeSentenceSentiment = optionsVO.getMinPunctuationWithExclamationToChangeSentenceSentiment();
classificationOptions.igMoodToInterpretNeutralEmphasis = optionsVO.getMoodToInterpretNeutralEmphasis();
// 与讽刺相关设置
classificationOptions.igMinSentencePosForQuotesIrony = optionsVO.getMinSentencePosForQuotesIrony();
classificationOptions.igMinSentencePosForPunctuationIrony = optionsVO.getMinSentencePosForPunctuationIrony();
classificationOptions.igMinSentencePosForTermsIrony = optionsVO.getMinSentencePosForTermsIrony();
// 自动纠正拼写
classificationOptions.bgCorrectSpellingsUsingDictionary = optionsVO.isCorrectSpellingsUsingDictionary();
classificationOptions.bgCorrectExtraLetterSpellingErrors = optionsVO.isCorrectExtraLetterSpellingErrors();
classificationOptions.sgIllegalDoubleLettersInWordMiddle = optionsVO.getIllegalDoubleLettersInWordMiddle();
classificationOptions.sgIllegalDoubleLettersAtWordEnd = optionsVO.getIllegalDoubleLettersAtWordEnd();
// 特殊情况
classificationOptions.bgMissCountsAsPlus2 = optionsVO.isMissCountsAsPlus2();
classificationOptions.bgYouOrYourIsPlus2UnlessSentenceNegative = optionsVO.isYouOrYourIsPlus2UnlessSentenceNegative();
classificationOptions.bgExclamationInNeutralSentenceCountsAsPlus2 = optionsVO.isExclamationInNeutralSentenceCountsAsPlus2();
// 其他
classificationOptions.bgExplainClassification = optionsVO.isExplainClassification();
classificationOptions.bgForceUTF8 = optionsVO.isForceUTF8();
classificationOptions.bgAlwaysSplitWordsAtApostrophes = optionsVO.isAlwaysSplitWordsAtApostrophes();
classificationOptions.bgUseLemmatisation = optionsVO.isUseLemmatisation();
if (!sentiStrength.setNewOptions(classificationOptions, refreshFlag))
throw new MyServiceException("SS006", "设置新的算法配置选项及资源失败!");
}
/**
* 查看算法配置选项
*
* @return OptionsVO 算法配置选项VO
*/
@Override
public OptionsVO getOptions() {
OptionsVO optionsVO = new OptionsVO();
ClassificationOptions classificationOptions = sentiStrength.getCurrentOptions();
// 算法逻辑设置
if (classificationOptions.bgScaleMode)
optionsVO.setClassificationMode("scale");
else if (classificationOptions.bgTrinaryMode) {
if (classificationOptions.bgBinaryVersionOfTrinaryMode)
optionsVO.setClassificationMode("binary");
else
optionsVO.setClassificationMode("trinary");
} else
optionsVO.setClassificationMode("default");
optionsVO.setEmotionParagraphCombineMethod(classificationOptions.igEmotionParagraphCombineMethod);
optionsVO.setEmotionSentenceCombineMethod(classificationOptions.igEmotionSentenceCombineMethod);
optionsVO.setAllowMultiplePositiveWordsToIncreasePositiveEmotion(classificationOptions.bgAllowMultiplePositiveWordsToIncreasePositiveEmotion);
optionsVO.setAllowMultipleNegativeWordsToIncreaseNegativeEmotion(classificationOptions.bgAllowMultipleNegativeWordsToIncreaseNegativeEmotion);
optionsVO.setMultipleLettersBoostSentiment(classificationOptions.bgMultipleLettersBoostSentiment);
optionsVO.setMinRepeatedLettersForBoost(classificationOptions.igMinRepeatedLettersForBoost);
optionsVO.setBoosterWordsChangeEmotion(classificationOptions.bgBoosterWordsChangeEmotion);
optionsVO.setCapitalsBoostTermSentiment(classificationOptions.bgCapitalsBoostTermSentiment);
optionsVO.setNegativeSentimentMultiplier(classificationOptions.fgNegativeSentimentMultiplier);
optionsVO.setReduceNegativeEmotionInQuestionSentences(classificationOptions.bgReduceNegativeEmotionInQuestionSentences);
// 算法考量范围
optionsVO.setUseIdiomLookupTable(classificationOptions.bgUseIdiomLookupTable);
optionsVO.setUseObjectEvaluationTable(classificationOptions.bgUseObjectEvaluationTable);
optionsVO.setUseEmoticons(classificationOptions.bgUseEmoticons);
// 与否定词相关设置
optionsVO.setNegatingWordsOccurBeforeSentiment(classificationOptions.bgNegatingWordsOccurBeforeSentiment);
optionsVO.setMaxWordsBeforeSentimentToNegate(classificationOptions.igMaxWordsBeforeSentimentToNegate);
optionsVO.setNegatingWordsOccurAfterSentiment(classificationOptions.bgNegatingWordsOccurAfterSentiment);
optionsVO.setMaxWordsAfterSentimentToNegate(classificationOptions.igMaxWordsAfterSentimentToNegate);
optionsVO.setNegatingWordsFlipEmotion(classificationOptions.bgNegatingWordsFlipEmotion);
optionsVO.setNegatingPositiveFlipsEmotion(classificationOptions.bgNegatingPositiveFlipsEmotion);
optionsVO.setNegatingNegativeNeutralisesEmotion(classificationOptions.bgNegatingNegativeNeutralisesEmotion);
optionsVO.setStrengthMultiplierForNegatedWords(classificationOptions.fgStrengthMultiplierForNegatedWords);
optionsVO.setIgnoreBoosterWordsAfterNegatives(classificationOptions.bgIgnoreBoosterWordsAfterNegatives);
// 与强调相关设置
optionsVO.setMinPunctuationWithExclamationToChangeSentenceSentiment(classificationOptions.igMinPunctuationWithExclamationToChangeSentenceSentiment);
optionsVO.setMoodToInterpretNeutralEmphasis(classificationOptions.igMoodToInterpretNeutralEmphasis);
// 与讽刺相关设置
optionsVO.setMinSentencePosForQuotesIrony(classificationOptions.igMinSentencePosForQuotesIrony);
optionsVO.setMinSentencePosForPunctuationIrony(classificationOptions.igMinSentencePosForPunctuationIrony);
optionsVO.setMinSentencePosForTermsIrony(classificationOptions.igMinSentencePosForTermsIrony);
// 自动纠正拼写
optionsVO.setCorrectSpellingsUsingDictionary(classificationOptions.bgCorrectSpellingsUsingDictionary);
optionsVO.setCorrectExtraLetterSpellingErrors(classificationOptions.bgCorrectExtraLetterSpellingErrors);
optionsVO.setIllegalDoubleLettersInWordMiddle(classificationOptions.sgIllegalDoubleLettersInWordMiddle);
optionsVO.setIllegalDoubleLettersAtWordEnd(classificationOptions.sgIllegalDoubleLettersAtWordEnd);
// 特殊情况
optionsVO.setMissCountsAsPlus2(classificationOptions.bgMissCountsAsPlus2);
optionsVO.setYouOrYourIsPlus2UnlessSentenceNegative(classificationOptions.bgYouOrYourIsPlus2UnlessSentenceNegative);
optionsVO.setExclamationInNeutralSentenceCountsAsPlus2(classificationOptions.bgExclamationInNeutralSentenceCountsAsPlus2);
// 其他
optionsVO.setExplainClassification(classificationOptions.bgExplainClassification);
optionsVO.setForceUTF8(classificationOptions.bgForceUTF8);
optionsVO.setAlwaysSplitWordsAtApostrophes(classificationOptions.bgAlwaysSplitWordsAtApostrophes);
optionsVO.setUseLemmatisation(classificationOptions.bgUseLemmatisation);
return optionsVO;
}
/**
* 设置算法资源
*
* @param resourcesVO 算法资源VO
*/
@Override
public void setResources(ResourcesVO resourcesVO) {
if (!sentiStrength.setResources(resourcesVO.getType(), resourcesVO.getList()))
throw new MyServiceException("SS007", "设置资源" + resourcesVO.getType() + "失败,请仔细检查资源文本及算法配置选项!");
}
/**
* 查看算法资源
*
* @param type 资源类型
* @return ResourcesVO 算法资源VO
*/
@Override
public ResourcesVO getResources(String type) {
ResourcesVO resourcesVO = new ResourcesVO();
resourcesVO.setType(type);
resourcesVO.setList(sentiStrength.getResources(type));
if (resourcesVO.getList() == null)
throw new MyServiceException("SS008", "获取资源" + type + "失败!");
else
return resourcesVO;
}
/**
* 重置算法资源为默认值
*
* @param type 资源类型
*/
@Override
public void resetResources(String type) {
if (!sentiStrength.resetResources(type))
throw new MyServiceException("SS009", "重置算法资源" + type + "为默认值失败!");
}
/**
* 一键复原算法资源为默认值
*/
@Override
public void resetResourcesAll() {
if (!sentiStrength.simpleInitialise())
throw new MyServiceException("SS010", "一键复原算法资源为默认值失败!");
}
/**
* 运行机器学习评估
*
* @param machineLearningVO 机器学习评估VO
* @return List<List < String>> 各结果文本按行存储的列表
*/
@Override
public List<List<String>> runMachineLearning(MachineLearningVO machineLearningVO) {
List<List<String>> ans;
ans = sentiStrength.runMachineLearning(
machineLearningVO.getInput(),
machineLearningVO.isTestAll(),
machineLearningVO.getMinImprovement(),
machineLearningVO.isUseTotalDifference(),
machineLearningVO.getIteration(),
machineLearningVO.getMultiOptimization());
if (ans == null || ans.size() < 3)
throw new MyServiceException("SS011", "机器学习评估运行失败!请保障有效的文本输入和恰当的数据量!");
else
return ans;
}
}
......@@ -21,17 +21,16 @@ public class UserServiceImpl implements UserService {
private final UserDao userDao;
public ClassificationOptions classificationOptions;
public ClassificationResources classificationResources;
@Autowired
public UserServiceImpl(UserDao userDao) {
this.userDao = userDao;
classificationOptions=new ClassificationOptions();
classificationResources=new ClassificationResources();
classificationResources.initialise(classificationOptions);
}
/**
* 用户注册
*
* @param userVO 用户信息VO
*/
@Override
public void register(UserVO userVO) {
UserPO current = userDao.findByUserName(userVO.getUsername());
......@@ -46,6 +45,13 @@ public class UserServiceImpl implements UserService {
userDao.register(userPO);
}
/**
* 用户登录
*
* @param username 用户名
* @param password 密码
* @return UserVO 用户信息VO
*/
@Override
public UserVO login(String username, String password) {
UserPO res = userDao.loginByUserName(username, password);
......@@ -58,10 +64,4 @@ public class UserServiceImpl implements UserService {
return ans;
}
@Override
public String action() {
return classificationResources.sentimentWords.getSentimentWord(2);
}
}
\ No newline at end of file
package com.sentistrength.service.Interface.sentistrength;
import com.sentistrength.model.vo.sentistrength.InputFileVO;
import com.sentistrength.model.vo.sentistrength.MachineLearningVO;
import com.sentistrength.model.vo.sentistrength.OptionsVO;
import com.sentistrength.model.vo.sentistrength.ResourcesVO;
import org.springframework.beans.factory.annotation.Autowired;
import uk.ac.wlv.sentistrength.SentiStrength;
import java.util.List;
public interface SentiStrengthService {
/**
* 对文本进行情感分析
*
* @param text 待分析的文本
* @return String 分析的结果
*/
String classifyText(String text);
/**
* 对文件中的各行文本进行情感分析
*
* @param inputFileVO 用户输入文件VO
* @return List<String> 分析的结果列表
*/
List<String> classifyFile(InputFileVO inputFileVO);
/**
* 对文件夹中的所有文件进行情感分析
*
* @param inputFileVOList 用户输入文件VO列表
* @return List<List < String>> 各文件的分析结果列表
*/
List<List<String>> classifyFiles(List<InputFileVO> inputFileVOList);
/**
* 设置算法配置选项
*
* @param optionsVO 算法配置选项VO
*/
void setOptions(OptionsVO optionsVO);
/**
* 查看算法配置选项
*
* @return OptionsVO 算法配置选项VO
*/
OptionsVO getOptions();
/**
* 设置算法资源
*
* @param resourcesVO 算法资源VO
*/
void setResources(ResourcesVO resourcesVO);
/**
* 查看算法资源
*
* @param type 资源类型
* @return ResourcesVO 算法资源VO
*/
ResourcesVO getResources(String type);
/**
* 重置算法资源为默认值
*
* @param type 资源类型
*/
void resetResources(String type);
/**
* 一键复原算法资源为默认值
*/
void resetResourcesAll();
/**
* 运行机器学习评估
*
* @param machineLearningVO 机器学习评估VO
* @return List<List < String>> 各结果文本按行存储的列表
*/
List<List<String>> runMachineLearning(MachineLearningVO machineLearningVO);
}
......@@ -5,10 +5,19 @@ import com.sentistrength.model.vo.user.UserVO;
import javax.print.DocFlavor;
public interface UserService {
/**
* 用户注册
*
* @param userVO 用户信息VO
*/
void register(UserVO userVO);
/**
* 用户登录
*
* @param username 用户名
* @param password 密码
* @return UserVO 用户信息VO
*/
UserVO login(String username, String password);
String action();
}
package com.sentistrength.web.controller.sentistrength;
import com.sentistrength.model.vo.sentistrength.InputFileVO;
import com.sentistrength.service.Interface.sentistrength.SentiStrengthService;
import com.sentistrength.service.Interface.user.UserService;
import com.sentistrength.web.Response;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(path = "/classification")
public class ClassificationController {
private final SentiStrengthService sentiStrengthService;
@Autowired
public ClassificationController(SentiStrengthService sentiStrengthService) {
this.sentiStrengthService = sentiStrengthService;
}
/**
* 对文本进行情感分析
*
* @param text 待分析的文本
* @return Response 返回前端的信息
*/
@GetMapping("/classifyText")
public Response classifyText(@RequestParam(value = "text") String text) {
return Response.buildSuccess(sentiStrengthService.classifyText(text));
}
/**
* 对文件进行情感分析
*
* @param inputFileVO 用户输入文件VO
* @return Response 返回前端的信息
*/
@PostMapping("/classifyFile")
public Response classifyFile(@RequestBody InputFileVO inputFileVO) {
return Response.buildSuccess(sentiStrengthService.classifyFile(inputFileVO));
}
/**
* 对文件夹中的所有文件进行情感分析
*
* @param inputFileVOList 用户输入文件VO列表
* @return Response 返回前端的信息
*/
@PostMapping("/classifyFiles")
public Response classifyFiles(@RequestBody List<InputFileVO> inputFileVOList) {
System.out.println(inputFileVOList.get(0).getColumn());
return Response.buildSuccess(sentiStrengthService.classifyFiles(inputFileVOList));
}
}
package com.sentistrength.web.controller.sentistrength;
import com.sentistrength.model.vo.sentistrength.MachineLearningVO;
import com.sentistrength.model.vo.sentistrength.ResourcesVO;
import com.sentistrength.service.Interface.sentistrength.SentiStrengthService;
import com.sentistrength.web.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(path = "/machineLearning")
public class MachineLearningController {
private final SentiStrengthService sentiStrengthService;
@Autowired
public MachineLearningController(SentiStrengthService sentiStrengthService) {
this.sentiStrengthService = sentiStrengthService;
}
/**
* 运行机器学习评估
*
* @param machineLearningVO 机器学习评估VO
* @return Response 返回前端的信息
*/
@PostMapping("/run")
public Response setResources(@RequestBody MachineLearningVO machineLearningVO) {
return Response.buildSuccess(sentiStrengthService.runMachineLearning(machineLearningVO));
}
}
package com.sentistrength.web.controller.sentistrength;
import com.sentistrength.model.vo.sentistrength.InputFileVO;
import com.sentistrength.model.vo.sentistrength.OptionsVO;
import com.sentistrength.service.Interface.sentistrength.SentiStrengthService;
import com.sentistrength.web.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(path = "/options")
public class OptionsController {
private final SentiStrengthService sentiStrengthService;
@Autowired
public OptionsController(SentiStrengthService sentiStrengthService) {
this.sentiStrengthService = sentiStrengthService;
}
/**
* 设置算法配置选项
*
* @param optionsVO 算法配置选项VO
* @return Response 返回前端的信息
*/
@PostMapping("/setOptions")
public Response setOptions(@RequestBody OptionsVO optionsVO) {
sentiStrengthService.setOptions(optionsVO);
return Response.buildSuccess();
}
/**
* 查看算法配置选项
*
* @return Response 返回前端的信息
*/
@GetMapping("/getOptions")
public Response getOptions() {
return Response.buildSuccess(sentiStrengthService.getOptions());
}
}
package com.sentistrength.web.controller.sentistrength;
import com.sentistrength.model.vo.sentistrength.OptionsVO;
import com.sentistrength.model.vo.sentistrength.ResourcesVO;
import com.sentistrength.service.Interface.sentistrength.SentiStrengthService;
import com.sentistrength.web.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(path = "/resources")
public class ResourcesController {
private final SentiStrengthService sentiStrengthService;
@Autowired
public ResourcesController(SentiStrengthService sentiStrengthService) {
this.sentiStrengthService = sentiStrengthService;
}
/**
* 设置算法资源
*
* @param resourcesVO 算法配置资源VO
* @return Response 返回前端的信息
*/
@PostMapping("/setResources")
public Response setResources(@RequestBody ResourcesVO resourcesVO) {
sentiStrengthService.setResources(resourcesVO);
return Response.buildSuccess();
}
/**
* 查看算法资源
*
* @param type 资源类型
* @return Response 返回前端的信息
*/
@GetMapping("/getResources")
public Response getResources(@RequestParam(value = "type") String type) {
return Response.buildSuccess(sentiStrengthService.getResources(type));
}
/**
* 重置算法资源为默认值
*
* @param type 资源类型
* @return Response 返回前端的信息
*/
@GetMapping("/resetResources")
public Response resetResources(@RequestParam(value = "type") String type) {
sentiStrengthService.resetResources(type);
return Response.buildSuccess();
}
/**
* 一键复原算法资源为默认值
*
* @return Response 返回前端的信息
*/
@GetMapping("/resetResourcesAll")
public Response resetResourcesAll() {
sentiStrengthService.resetResourcesAll();
return Response.buildSuccess();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment