「java分析文本语义」java语义分析开源库
本篇文章给大家谈谈java分析文本语义,以及java语义分析开源库对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、java语义分析
- 2、这里的语义指什么?能否举一例(JAVA)
- 3、那个大神知道java中文语义分析是什么啊
- 4、Java解析复杂文本
- 5、java中的文本分析
- 6、java怎样调用bosonnlp的库来判断语义
java语义分析
public class VariableTypeResolver {
private final String symbol;
private final ASTNode minScope;
private boolean methodLevel = true;
private boolean typeLevel = true;
/**
* The found result
*/
private SimpleName declSN;
private final ASTVisitor visitor = new ASTVisitor() {
@Override
public boolean visit(SimpleName sn) {
if (found()) {
return false;
}
if (sn.getIdentifier().equals(symbol) sn.getParent() instanceof VariableDeclaration) {
declSN = sn;
return false;
}
return true;
}
};
/**
* Starts resolving with the requested symbol
* @param varSymbolNode the variable symbol node to resolve (node must be in the AST)
*/
public VariableTypeResolver(SimpleName varSymbolNode) {
this.symbol = varSymbolNode.getIdentifier();
this.minScope = varSymbolNode;
}
public VariableTypeResolver(String varSymbol, ASTNode minScope) {
this.symbol = varSymbol;
this.minScope = minScope;
}
public VariableTypeResolver disableMethodLevel() {
methodLevel = false;
return this;
}
public VariableTypeResolver disableTypeLevel() {
typeLevel = false;
return this;
}
/**
* Node's parent is instance of {@link VariableDeclarationFragment} or {@link SingleVariableDeclaration}
* @return the SimpleName node of declaration
*/
public SimpleName resolveDeclSimpleName() {
if (!found()) {
resolve();
}
return declSN;
}
private void resolve() {
if(found()) {return;}
if (methodLevel) {
apply(FindUpper.methodScope(minScope));
}
if(found()) {return;}
if (typeLevel) {
AbstractTypeDeclaration typeScope = FindUpper.abstractTypeScope(minScope);
applyInFields(typeScope);
if(found()) {return;}
for (TypeDeclaration superClass : superClasses(typeScope)) {
if(found()) {return;}
applyInFields(superClass);
}
}
}
private boolean found() {
return declSN != null;
}
private void apply(ASTNode scope) {
if (scope == null) {
throw new NullPointerException();
}
scope.accept(visitor);
}
private void applyInFields(AbstractTypeDeclaration typeScope) {
for (Object bd : typeScope.bodyDeclarations()) {
if (bd instanceof FieldDeclaration) {
apply((ASTNode) bd);
}
}
}
private ListTypeDeclaration superClasses(AbstractTypeDeclaration atd) {
if (atd instanceof TypeDeclaration) {
return AstUtils.superClasses((TypeDeclaration) atd);
}
else {
return Collections.EMPTY_LIST;
}
}
}
也是网上找的
这里的语义指什么?能否举一例(JAVA)
比如我要写一个游戏角色,用很多代码去写:发声,跑,攻击,贴图等等。
但我给这个复杂代码组成的对象起名“Dog”,Dog对象就是对这个复杂运行机制的抽象化。
Dog的语义-狗就是所谓“外观”或者外在概括,,但这个dog不是动物意义上的狗,而是抽象命名的某应用域中的自定义概念.
那个大神知道java中文语义分析是什么啊
就是逻辑分析。比如1/0,词法和语法分析都没有问题,但是零不能做分母,所以语义分析错了。
Java解析复杂文本
import java.io.*;
import java.util.*;
public class FileManager {
public ListDishes parseFile(File file) {
String str = null;
ListDishes list = new ArrayListDishes();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
while((str = br.readLine())!=null) {
if(str.startsWith("Name:")) {
int index = str.indexOf(":");
String dishName = str.substring(index+1,str.length());
str = br.readLine();
index = str.indexOf(":");
String categoriesString = str.substring(index+1,str.length());
String[] cateArr = categoriesString.split(",");
SetString categories = new HashSetString();
for(int j = 0;jcateArr.length;j++) {
categories.add(cateArr[j]);
}
SetString ingredients = new HashSetString();
String ss = br.readLine();
while((str = br.readLine()) != null !(str.length() == 0)) {
String[] strArr = str.split(" ");
for(int i = 0;istrArr.length;i++) {
ingredients.add(strArr[i]);
}
}
Dishes d = new Dishes();
d.setName(dishName);
d.setCategories(categories);
d.setIngredients(ingredients);
list.add(d);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FileManager fm = new FileManager();
ListDishes list = new ArrayListDishes();
File file = new File("D:/dishes.txt");
list = fm.parseFile(file);
for(int i = 0; ilist.size();i++) {
System.out.println(list.get(i).getName());
System.out.println(list.get(i).getCategories());
System.out.println(list.get(i).getIngredients());
}
}
}
//菜肴类,一种菜对应于菜肴类的一的实例
class Dishes {
private String name;
private SetString Categories; //菜肴类别
private SetString ingredients; //菜肴配料
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public SetString getCategories() {
return Categories;
}
public void setCategories(SetString categories) {
Categories = categories;
}
public SetString getIngredients() {
return ingredients;
}
public void setIngredients(SetString ingredients) {
this.ingredients = ingredients;
}
}
java中的文本分析
BufferedReader br = new BufferedReader(new FileReader(要找的文件路径));
StringBuffer sb = br.readLine();
Pattern pattern = pattern.compile("(//d{3})(//d{3})(//d{1})(//d{10})");
Matcher m = pattern.matcher(sb);
while(m.find()) {
System.out.println(m.group());
}
可能不是您要的解决方法。不过大多数查找数据都是这个思路。
java怎样调用bosonnlp的库来判断语义
去maven仓库查找相应的jar,仓库地址
搜索关键字:bosonnlp
网页链接,找到一个这样的jar不知道是不是你要的,可根据自己情况自行在maven搜索
在pom.xml添加以下引用:
!-- --
dependency
groupIdclj-bosonnlp/groupId
artifactIdclj-bosonnlp/artifactId
version0.1.2/version
/dependency
之后直接拿ide打开,直接查看jar包内容,找自己需要的东西。
api文档参考:网页链接
关于java分析文本语义和java语义分析开源库的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-11-30,除非注明,否则均为
原创文章,转载请注明出处。