上传备份

master
王兵 5 months ago
commit a62a5d3968

21
.gitignore vendored

@ -0,0 +1,21 @@
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
/.idea
*.iml
/.settings
/bin
/gen
/build
/gradle
/classes
.classpath
.project
*.gradle
gradlew
local.properties
node_modules/
data/

@ -0,0 +1 @@
## 自然语言学习

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.wbsite</groupId>
<artifactId>starter-nlp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<java.version>17</java.version>
<!-- 需要jdk17以上 -->
<langchain4j.version>1.0.0-beta2</langchain4j.version>
</properties>
<repositories>
<!-- 将中央仓库地址指向阿里云聚合仓库,提高下载速度 -->
<repository>
<id>central</id>
<name>Central Repository</name>
<layout>default</layout>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
</repositories>
<pluginRepositories>
<!-- 将插件的仓库指向阿里云聚合仓库解决低版本maven下载插件异常或提高下载速度 -->
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://maven.aliyun.com/repository/public</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- 糊涂工具包含常用API避免重复造轮子 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.24</version>
</dependency>
<!-- 然语言处理工具包 -->
<dependency>
<groupId>com.hankcs</groupId>
<artifactId>hanlp</artifactId>
<version>portable-1.8.4</version>
</dependency>
<!-- 日志框架 -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j</artifactId>
<version>${langchain4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

@ -0,0 +1,44 @@
package xyz.wbsite.ai;
import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.corpus.tag.Nature;
import com.hankcs.hanlp.seg.common.Term;
import com.hankcs.hanlp.tokenizer.StandardTokenizer;
import java.util.List;
public class HanLP_Example {
public static void main(String[] args) {
// HanLPTokenizer hanLPTokenizer = new HanLPTokenizer();
// String[] segment = hanLPTokenizer.segment("我喜欢吃苹果");
//
// List<String> 我喜欢吃苹果1 = HanLP.extractKeyword("我喜欢吃苹果", 2);
//
// HanLPEngine hanLPEngine = new HanLPEngine();
// Result parse = hanLPEngine.parse("我喜欢吃苹果");
//
//
// for (Word word : parse) {
// System.out.println(word);
// }
List<String> strings = HanLP.extractKeyword("身份证去哪里办理", 1);
List<String> string = HanLP.extractKeyword("需要带什么材料", 1);
// 分词
List<List<Term>> lists = StandardTokenizer.seg2sentence("那么还需要哪些材料");
for (List<Term> list : lists) {
for (Term term : list) {
System.out.println(term);
// 检查词性是否为主语相关的词性(例如:主谓宾中的主语通常是名词或代词)
// if (term.nature.equals(Nature.n)) { // 名词
// System.out.println("主语: " + term);
// }
// if (term.nature.equals(Nature.r)) { // 代词,例如“他”、“她”等
// System.out.println("主语: " + term);
// }
}
}
}
}
Loading…
Cancel
Save

Powered by TurnKey Linux.