Skip to content

liuxun666/flashtext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 

Repository files navigation

flashtext

flashtext find keyword in text

scala version 2.11

<dependency>
  <groupId>com.github.liuxun666</groupId>
  <artifactId>flashtext</artifactId>
  <version>1.4.9_2.11</version>
</dependency>

scala :

val keywords = Array("拒绝","办法" ,"怎么办","么办法" ,"怎么" ,"离婚")
val dict = DictUtils.loadDict(keywords)
Analyzer.analyze("怎么有办法离婚", dict, Compare.ENDFIRST).foreach(println)

val map = Map("北京" -> 110000, "成都" -> 510100)
val dict2 = DictUtils.loadDict(map)
Analyzer.analyze("明天飞北京", dict, Compare.ENDFIRST).foreach(println)
Analyzer.analyze("明天飞北京", dict, (w1, w2) => w1.begin - w2.begin).foreach(println)

java:

String[] keywords = new  String[]{"拒绝","办法" ,"怎么办","么办法" ,"怎么" ,"离婚"};
Dictionary dict = DictUtils.loadDict(keywords);
Word[] finded = Analyzer.analyze("怎么有办法离婚", dict, true);
Map<String, Integer> map = new HashMap();
map.put("北京", 110000);
map.put("成都", 510100);
Dictionary dict = DictUtils.loadDict(map);
// 控制排序方式
Word<Integer>[] finded = Analyzer.analyze("明天飞北京", dict, true, Compare.ENDFIRST());  
Word<Integer>[] finded = Analyzer.analyze("明天飞北京", dict, true, (w1, w2) -> w1.end() - w2.end());  

deploy: mvn clean package net.alchim31.maven:scala-maven-plugin:4.0.2:doc-jar deploy -P sonatype-oss-release -f pom.xml