拆分、匹配关键字
如何在一篇文章内拆分和匹配关键字?例如以下文章:
姐弟恋真的没好结果吗?我老公比我小五岁,我们刚结婚那会几乎天天吵,本来感情基础就没打好,结婚不久又有了孩子,孩子现在三岁了,在这三年里不知吵了多少会,可能现实生活就是这样的,两口子可能都吵过架,后来经过几次吵架,我也懂得了很多,两个人就的互相体谅,互相包容,忍让对方。我老公比较孩子气,动不动就发火,一点小事就生气,我们在一起这几年几乎没出去玩过,也没合过影,老公花钱也是没个计划,讲究名牌,吃也的要好的,不让买就生气要不不理你,自己老是有理的不行,我们收入一般,他的花销远远超出我们的收入,我是急在心里也不知怎么办,因为他不听你说,他还挺高傲自己认为别人都不如他,说我是傻逼,什么也不懂,真不知道你怎么长大的,就这样我也忍了,谁让我当初选的,还有为了孩子我可以忍,就是希望有一天他能发现自己也有错误,可是最近我发现我越忍让他越张狂,出去干活了,就的给你找点事干,说我出去挣钱养你们,你就不能闲着,好了你说干什么我干忍了,看见我没穿袜子说把我脚剁了,我也忍了,我不想和他吵没意思的,晚上回来饭做好了,吃了饭要吃烤红薯,我说给你弄去,需要买去,他说他姐夫说跑黑车,我说你也去吧,就这句话不爱听了,说我掉钱眼里了,就急了说我什么也不想,就会瞎BB,反正什么难听说什么,说我不干活,怎么不我不去挣钱,我说现在孩子小不能自理,我管好孩子就是我的任务,你应该出去挣钱,我说等子上学了我自然就挣去了,我说了他应该管,又不对,说凭什么我应该管你们呀,又急了就开始发疯了一直在说些他自己认为的事把我想想的特别坏,还的让你承认他说的对,我无语了不说了,让着他让他说,他又嫌你不说,我说你大人不计小人过我错了你就包容我一下吧别生气他说不行没完接着又是一顿数落,我现在都不知该如何是好,我忍让他那么多是让他从中得到点领悟,人无完人,把自己不对的也改改,发现点自己的缺点,但是没有反而更猖狂了,我又不是一个智慧的女人我现在该怎么办,希望大家帮帮忙,我很需要你们谢谢啦!
我想在用户发表该文章时,把文章的某些词语记录下来作为关键字以作他用。有没有什么算法/思路可以实现这个需求呢?还是只能人工阅读然后总结/抽出关键字?
------解决方案--------------------
1.有关键词表(可以添加)
2.计算关键词频率
不要自己做分词,呵呵
编辑(这里指的人/职位)还是需要的
------解决方案--------------------
1 系统关键字表, 会自动匹配替换关键字。
2 用户录入时指定关键字
------解决方案--------------------
说明:
1、我使用的编码是 gbk 的,如果是 utf-8 的请自行删除有关编码的部分
2、处理用的文档时楼主贴出的示例文字
3、代码是现写的,有关算法问题请指正
iconv_set_encoding("internal_encoding", "utf-8");<br>iconv_set_encoding("output_encoding", "gbk");<br>ob_start("ob_iconv_handler"); <br><br>$fn = '如何在一篇文章内拆分和匹配关键字_例文.txt';<br><br>$p = new T;<br>$ar = $p->parse($fn);<br>print_r($ar);<br>//print_r($p->dat);<br><br>class T {<br> var $maxlen = 4;//最大组词长度<br> var $dat = array();<br> var $dict = array();<br> function get($offs=0) {<br> if($this->i + $offs >= $this->len <br><font color="#FF8000">------解决方案--------------------</font><br> $offs >= $this->maxlen) return false;<br> $ch = $this->doc[$this->i + $offs];<br> if(in_array($ch, $this->dict)) return false;<br> return $ch;<br> }<br> function parse($filename) {<br> $this->dict = explode('<br><font color="#FF8000">------解决方案--------------------</font><br>', iconv('gbk', 'utf-8', ',<br><font color="#FF8000">------解决方案--------------------</font><br>。<br><font color="#FF8000">------解决方案--------------------</font><br>;<br><font color="#FF8000">------解决方案--------------------</font><br>:<br><font color="#FF8000">------解决方案--------------------</font><br>“<br><font color="#FF8000">------解决方案--------------------</font><br>”<br><font color="#FF8000">------解决方案--------------------</font><br>?'));<br> $s = file_get_contents($filename);<br> $s = iconv('gbk', 'utf-8', $s);<br> preg_match_all('/./u', $s, $r);<br> $this->doc = $r[0];<br> $this->i = 0;<br> $this->len = count($this->doc);<br> while($this->i len) {<br> if(($ch = $this->get()) !== false) {<div class="clear"> </div>

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)