GithubHelp home page GithubHelp logo

yuzhongxin19860213 / keyword Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xhlian/keyword

1.0 1.0 0.0 290 KB

关键词过滤、替换、高亮、统计算法

License: Apache License 2.0

Java 100.00%

keyword's Introduction

keyword

关键词过滤、替换、高亮、统计算法.
对1万字的文章、1千关键词进行筛选,一秒内可执行2000次,平均耗时0.5毫秒。
不依赖其它第三方工具库。
参考了https://github.com/jmhsieh/aho-corasick。

典型用法如下:

KeywordFilterBuilder builder = new KeywordFilter();
// 设置关键词   
builder.setKeywords( Arrays.asList("心情", "哈哈", "敏感词1", "敏感词2") );   
// 设置跳过字符   
builder.setSkipChars( Arrays.asList('*', '_',  ',',  '.',  '-') );   
final KeywordFilter filter = builder.build();  
// 统计关键字出现次数                         
filter.count( "老龙恼怒闹老农,老农恼怒闹老龙。", "老龙" );     // 2          
filter.count( "老*龙恼怒闹老农,老农恼怒闹老_龙。", "老龙" );   // 2         

// 替换关键字                  
filter.replace( "买彩票中奖了,哈哈", new ReplaceStrategy() {             
        public String replaceWith(String keywords) {                       
             return "呵呵";                                                     
        }                                                      
}); 
// return "买彩票中奖了,呵呵".  
                                             
// 判断是否包含关键词           
filter.hasKeywords( "今天天气不错,心情也跟着好起来了" );      // true  
filter.hasKeywords( "今天天气不错,心*情也跟着好起来了" );      // true

keyword's People

Contributors

xhlian avatar

Stargazers

ssm avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.