精华内容
下载资源
问答
  • 关键词查找

    2018-05-10 19:59:05
    #include<stdio.h>02int main() {03 char word[6][50];04 int num[5] = { 0 };05 int i, j, k,flag;06 for (i = 0;i <= 5;i++) {07 scanf("%s"...09 ...
    #include<stdio.h>
    02int main() {
    03    char word[6][50];
    04    int num[5] = { 0 };
    05    int i, j, k,flag;
    06    for (i = 0;i <= 5;i++) {
    07        scanf("%s", word[i]);
    08        fflush(stdin);
    09    }
    10    for (k = 0;k < 5;k++) {
    11        for (i = 0;word[5][i] != '\0';i++) {
    12            if (word[k][0] == word[5][i]) {
    13                for (j =0;word[k][j] != '\0';j++) {
    14             
    15                    if (word[k][j] == word[5][i+j])
    16                        flag = 1;
    17                    else
    18                    {
    19                        flag = 0;break;
    20                    }
    21                }
    22                if (flag == 1) num[k]++;
    23 
    24            }
    25 
    26            }
    27        }
    28    for (i = 0;i < 5;i++) {
    29        printf("%d", num[i]);
    30        printf("\n");
    31    }
    32    return 0;
    33    }
    34    

    Contest Hun

    展开全文
  • jQuery关键词查找高亮显示代码,在搜索框输入关键词查找元素文字高亮显示效果代码。
  • Unity里面实现简单关键词查找 ******************************************************************************/ using UnityEngine; using System.Collections; using System.Collections.Generic; namespace ...

    Unity里面实现简单关键词查找

    ******************************************************************************/
    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    namespace Com.Rainier.WangJing
    {
    	public class KeySearch : MonoBehaviour 
    	{
            public static KeySearch Instance;
            private void Awake()
            {
                Instance = this;
            }
            void Start () 
    		{	
    		}
            /// <summary>
            /// 关键词检索结果
            /// </summary>
            public struct KeySearchResult
            {
                public bool isContain;//是否匹配到关键词
                public int keyCount;//匹配到的关键字个数
                public List<int> keyIndex;//匹配到的关键词索引
            }
            /// <summary>
            /// 关键词匹配
            /// </summary>
            public KeySearchResult IsKeySearch(string inputStr, string[] targetKey)
            {
                KeySearchResult result = new KeySearchResult();
                result.keyIndex = new List<int>();
                for (int i = 0; i < targetKey.Length; i++)
                {
                    string key = targetKey[i];
                    if (inputStr.Contains(key))
                    {
                        result.isContain = true;
                        result.keyCount++;
                        result.keyIndex.Add(i);
                    }
                }
                return result;
            }
        }
    }
    
    
    

    有问题请指出,谢谢!

    展开全文
  • 1、多关键词查找普通的场景下,想要从一个字符串中找到一个关键字,可以使用字符串的find方法target = 'this is a book' print(target.find('book'))如果想要查找的关键词有多个,仍然可以使用find方法,它并没有你...

    0c6d503f628831a41769b8f6eb4c3f53.png

    1、多关键词查找

    普通的场景下,想要从一个字符串中找到一个关键字,可以使用字符串的find方法

    target = 'this is a book'
    print(target.find('book'))

    如果想要查找的关键词有多个,仍然可以使用find方法,它并没有你想象中那么慢,但如果关键词的数量继续上升,你就应该使用正则表达式来处理,不论是性能还是程序的编写难度都优于使用find方法

    import re
    target = '但如果关键词的数量继续上升,你就应该使用正则表达式来处理,不论是性能还是程序的编写难度都优于使用find方法'
    pattern = re.compile("(关键词|正则表达式|性能)")
    res = pattern.findall(target)
    print(res)

    当关键词的数量继续上升,达到数万个甚至更多时,正则表达式的性能也会开始变得难以接受,对于正则表达式,我们要明白一点,我们用它表达一个字符串模式时,它的确是万能的,没有正则搞不定的模式,但是这个模式在匹配时,性能层面上却不是万能的。甚至有人打趣到,如果你处理问题时,想到了使用正则,那么恭喜你,你的问题变成了两个。

    2、flashtext

    Flashtext 算法是一个高效的字符搜索和替换算法。该算法的时间复杂度不依赖于搜索或替换的字符的数量,这就意味着哪怕是几十万,几百万个关键词,其查找的时间复杂度仍然只取决于文档的长度,而与关键词数量无关。

    假设一个文档的长度是N,有M个关键词,使用flashtext 的时间复杂度是O(N),使用正则表达式的时间复杂度是O(M * N),现在,你一定很关心如何使用flashtext,以及flashtext和正则表达式的性能对比究竟如何。

    网上能找到的相关文章,都在讲flashtext如何如何快,贴出各种性能测试结果,但却没有提供实验方法和示例,或许是由于需要的文档数量太多了,大家都不愿意做这方面的准备,为了学习flashtext并验证其性能,我做了一个简单的实验,对比正则和flashtext的性能。

    3、 实验对比正则和flashtext的性能

    第一步, 准备关键词

    只有关键词的数量非常大时,flashtext的优势才明显,否则,不要说正则,连字符串find方法都非常快。哪里找那么多关键词呢,我想到了小说。

    随便下载了一个网络小说《学霸是个特困生.txt》,使用结巴分词对小说进行分词处理,去掉长度为1的词,保存剩余的关键词到文件words中,关键词共有4万9千个

    第二步, 测试正则的速度

    从文件words文件读取关键词,使用 | 连接在一起,作为正则表达式 ,仍然使用小说的内容作为文档进行关键词查找

    第三步,测试flashtext

    从文件words文件读取关键词,创建KeywordProcessor对象,添加关键词,使用extract_keywords方法提取关键词

    实验结果,使用正则表达式耗时14.289秒,flashtext耗时0.4092秒,flashtext快了35倍

    4、 示例代码

    小说文件,我这里就不提供了,网上随便找一个就可以用

    import re
    import time
    import jieba
    
    
    def cost(func):
        def warpper():
            t1 = time.time()
            res = func()
            t2 = time.time()
            print(func.__name__ + "执行耗时" + str(t2-t1))
            return res
        return warpper
    
    
    story_file = '/Users/kwsy/Desktop/学霸是个特困生.txt'
    
    
    def get_file_data(filename):
        """
        读取文件数据
        :param filename:
        :return:
        """
        with open(filename, 'r', encoding='utf-8')as f:
            return f.read()
    
    
    def cut_word():
        """
        生成关键词
        :return:
        """
        data = get_file_data(story_file)
        with open('words', 'w', encoding='utf-8')as word_file:
            word_lst = jieba.lcut(data)
            for word in word_lst:
                if len(word) == 1:
                    continue
                word_file.write(word+"n")
    
    
    def get_key_word():
        """
        读取关键词
        :return:
        """
        with open('words')as f:
            data = f.read()
            word_lst =data.split("n")
            return word_lst
    
    @cost
    def find_by_re():
        """
        正则表达式查找关键词
        :return:
        """
        word_lst = get_key_word()
        pattern = re.compile("|".join(word_lst))
        story_data = get_file_data(story_file)
        res = pattern.findall(story_data)
        # print(res)
    
    @cost
    def find_by_flashtext():
        """
        使用flashtext查找关键词
        :return:
        """
        from flashtext.keyword import KeywordProcessor
        word_lst = get_key_word()
        keyword_processor = KeywordProcessor()
        for word in word_lst:
            keyword_processor.add_keyword(word)
    
        story_data = get_file_data(story_file)
        keywords_found = keyword_processor.extract_keywords(story_data)
        #print(keywords_found)
    
    cut_word()
    find_by_re()
    find_by_flashtext()
    展开全文
  • 特效描述:列表文字表单 文本框输入 关键词查找表单。代码结构1. 引入CSS2. 引入JS3. HTML代码jQuery关键词查找元素高亮代码伟大的吉萨金字塔The Great Pyramid of Giza (also known as the Pyramid of Khufu or the...

    特效描述:列表文字表单 文本框输入 关键词查找表单。

    代码结构

    1. 引入CSS

    2. 引入JS

    3. HTML代码

    jQuery关键词查找元素高亮代码

    • 伟大的吉萨金字塔

      The Great Pyramid of Giza (also known as the Pyramid of Khufu or the Pyramid of Cheops) is the oldest and largest of the three pyramids in the Giza Necropolis bordering what is now El Giza, Egypt. It is the oldest of the Seven Wonders of the Ancient World, and the only one to remain largely intact.

    • 巴格达空中花园

      The Hanging Gardens of Babylon were one of the Seven Wonders of the Ancient World, and the only one whose location has not been definitely established.

      The Hanging Gardens were a distinctive feature of ancient Babylon. They were a great source of pride to the people, and were often described in accounts written by visitors to the city. Possibly built by King Nebuchadnezzar II in 600 BC, the gardens are believed to have been a remarkable feat of engineering: an ascending series of tiered gardens containing all manner of trees, shrubs, and vines. The gardens were said to have looked like a large green mountain constructed of mud bricks, rising from the center of the city.

    • 第九站长

      The Statue of Zeus at Olympia was a giant seated figure, about 13 m (43 ft) tall, made by the Greek sculptor Phidias around 435 BC at the sanctuary of Olympia, Greece, and erected in the Temple of Zeus there. A sculpture of ivory plates and gold panels over a wooden framework, it represented the god Zeus sitting on an elaborate cedar wood throne ornamented with ebony, ivory, gold and precious stones. It was regarded as one of the Seven Wonders of the Ancient World until its eventual loss and destruction during the 5th century AD. No copy of the statue has ever been found, and details of its form are known only from ancient Greek descriptions and representations on coins.

    • 阿耳忒弥斯神庙

      The Temple of Artemis or Artemision (Greek: Ἀρτεμίσιον, Turkish: Artemis Tapınağı), also known less precisely as the Temple of Diana, was a Greek temple dedicated to the goddess Artemis and is one of the Seven Wonders of the Ancient World. It was located in Ephesus (near the modern town of Selçuk in present-day Turkey), and was completely rebuilt three times before its eventual destruction in 401. Only foundations and sculptural fragments of the latest of the temples at the site remain.

    • Mausoleum at Halicarnassus

      The Mausoleum at Halicarnassus or Tomb of Mausolus (Persian: آرامگاه هالیکارناسوس‎; Modern Greek: Μαυσωλείο της Αλικαρνασσού; Turkish: Halikarnas Mozolesi) was a tomb built between 353 and 350 BC at Halicarnassus (present Bodrum, Turkey) for Mausolus, a satrap in the Persian Empire, and Artemisia II of Caria, who was both his wife and his sister. The structure was designed by the Greek architects Satyros and Pythius of Priene.

    • Colossus of Rhodes

      The Colossus of Rhodes /roʊdz/ (Ancient Greek: ὁ Κολοσσὸς Ῥόδιος ho Kolossòs Rhódios) was a statue of the Greek titan-god of the sun Helios, erected in the city of Rhodes, on the Greek island of the same name, by Chares of Lindos in 280 BC. It is one of the Seven Wonders of the Ancient World. It was constructed to celebrate Rhodes' victory over the ruler of Cyprus, Antigonus I Monophthalmus, whose son unsuccessfully besieged Rhodes in 305 BC. Before its destruction in the earthquake of 226 BC, the Colossus of Rhodes stood over 30 metres (98 feet) high, making it one of the tallest statues of the ancient world.

    • Lighthouse of Alexandria

      The Lighthouse of Alexandria, sometimes called the Pharos of Alexandria (/ˈfɛərɒs/; Ancient Greek: ὁ Φάρος τῆς Ἀλεξανδρείας), was a lighthouse built by the Ptolemaic Kingdom between 280 and 247 BC which was between 393 and 450 ft (120 and 137 m) tall. It was one of the tallest man-made structures in the world for many centuries, and was regarded as one of the Seven Wonders of the Ancient World. Badly damaged by three earthquakes between AD 956 and 1323, it then became an abandoned ruin. It was the third longest surviving ancient wonder (after the Mausoleum at Halicarnassus and the extant Great Pyramid of Giza) until in 1480 the last of its remnant stones were used to build the Citadel of Qaitbay on the site. In 1994, French archaeologists discovered some remains of the lighthouse on the floor of Alexandria's Eastern Harbour.

    No matches were found… Try “giza”.

    'use strict';

    // search & highlight

    ;( function( $, window, document, undefined )

    {

    var $container = $( '.faq' );

    if( !$container.length ) return true;

    var $input= $container.find( 'input' ),

    $notfound= $container.find( '.faq__notfound' ),

    $items= $container.find( '> ul > li' ),

    $item= $(),

    itemsIndexed= [];

    $items.each( function()

    {

    itemsIndexed.push( $( this ).text().replace( /\s{2,}/g, ' ' ).toLowerCase() );

    });

    $input.on( 'keyup', function( e )

    {

    if( e.keyCode == 13 ) // enter

    {

    $input.trigger( 'blur' );

    return true;

    }

    $items.each( function()

    {

    $item = $( this );

    $item.html( $item.html().replace( /([^/gi, '$1' ) );

    });

    var searchVal = $.trim( $input.val() ).toLowerCase();

    if( searchVal.length )

    {

    for( var i in itemsIndexed )

    {

    $item = $items.eq( i );

    if( itemsIndexed[ i ].indexOf( searchVal ) != -1 )

    $item.removeClass( 'is-hidden' ).html( $item.html().replace( new RegExp( searchVal+'(?!([^)', 'gi' ), '$&' ) );

    else

    $item.addClass( 'is-hidden' );

    }

    }

    else $items.removeClass( 'is-hidden' );

    $notfound.toggleClass( 'is-visible', $items.not( '.is-hidden' ).length == 0 );

    });

    })( jQuery, window, document );

    // toggling items on title press

    ;( function( $, window, document, undefined )

    {

    $( document ).on( 'click', '.faq h2 a', function( e )

    {

    e.preventDefault();

    $( this ).parents( 'li' ).toggleClass( 'is-active' );

    });

    })( jQuery, window, document );

    // auto-show item content when show results reduces to single

    ;( function( $, window, document, undefined )

    {

    var $container = $( '.faq' );

    if( !$container.length ) return true;

    var $input= $container.find( 'input' ),

    $items= $container.find( '> ul > li' ),

    $item= $();

    $input.on( 'keyup', function()

    {

    $item = $items.not( '.is-hidden' );

    if( $item.length == 1 )

    $item.addClass( 'js--autoshown is-active' );

    else

    $items.filter( '.js--autoshown' ).removeClass( 'js--autoshown is-active' );

    });

    })( jQuery, window, document );

    展开全文
  • 之前旧的php系统有一个关键词查找和敏感词过滤的功能,直接使用了如下代码实现, foreach ($words as $word){ if(strrpos($content, $word) !== false){ $tags[] = $word; } ...
  • linux中vi怎么根据关键词查找

    千次阅读 2017-08-17 14:06:29
    我们都知道日志内容常常是非常多的,那么当我们vi日志时,怎么根据关键词查找呢. 1,vi编辑下,直接敲斜杠"/" ,此时在界面的状态栏,即界面最下方会出现"/" 2,直接输入要查找的关键词,再enter键回车即可 3,如果要查找...
  • C++实现轻量级的关键词查找系统

    千次阅读 2018-12-31 20:35:33
    多数游戏中,都会提供关键词查找的功能,即通过输入一个子串,最终返回所有包含该子串的记录; 具体的应用场景包括:陌生人查找, 公会查找,消息记录查找等等。 对于这类需求,查找的数据范围往往会很广,如果是...
  • 和关键词提取一样,关键词查找使用相同的算法和统计模型将输入流中的字符串按照名词或者名词词组进行统计,不同的是它参照一个已经存在的词汇表,输出的统计结果也仅限于这个词汇表中的关键词。关键词提取和关键词...
  • 如何打开PDF文件根据关键词查找内容呢?1、简单查找打开PDF文档我们一般会用到PDF阅读器,而很多阅读器一般都有查找功能,例如我们用极速PDF阅读器打开文档后,直接点击工具栏“查找”或快捷键“Ctrl+F”即可打开...
  • python 按关键词查找遍历所有文件和目录, 当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件 其中最下面的if语句为测试代码部分,当输入'123'时,会打印当前目录和当前目录的所有子目录下包含'...
  • 想用百度通过关键词查找CSDN类文章时,发现百度显示出来的目标网站除了广告类网站在结果页面显示具体的url外,其他网站的url基本被屏蔽。无奈之下,只能通过点击的方式获取目标网站的url,并对广告类的网站过了过滤...
  • 说实话,该博客排版太零乱,但是不影响关键词查找。转发过来以供以后参考:http://blog.sina.com.cn/s/blog_9f488855010179pt.html 1.内置运算符 1.1关系运算符 运算符 类型 说明 A =...
  • 根据关键词查找文件

    2017-09-20 20:54:49
    在linux下如果要查找包含某个关键字的文件,如要在根目录下搜索带有关键字“http”的文件,在终端下运行命令:  find / –type f |xargs grep “http”  或者  grep -r "http" /root/
  • 以前一直用cat ./*|grep 'keyword' 但是最后因为文件量太大 不知道具体在哪个文件里面 grep -nHIrF KeyWord ./ 做个记录 转载于:https://www.cnblogs.com/coffiasd/p/9996792.html...
  • item_search - 根据关键词取商品列表 测试网址:http://console.open.onebound.cn/console/?i=Turbo Result Object: { “items”: { “keyword”: “NIKE”, “page”: “1”, “real_total_results”: 135, ...
  • 原文:资源 | 十五分钟完成Regex五天任务:FastText,语料库数据快速清理利器 ...性能:案例:字符串查找英文:# pip install flashtext from flashtext.keyword import KeywordProcessor keyword_processor = Keywor
  • tail【常用】 tail -1000f nohup.out tail -n 100 nohup.out grep【常用】 ...多关键词 或 grep -E "资金方|核心企业|供应商" nohup.out --color 多关键词 与 grep '2019-08-16 10:00' nohup.out | ...
  • Linux根据关键词查找系统日志

    千次阅读 2016-09-05 11:57:27
    Cat命令 语法 cat -n catalina.out | grep "搜索的关键词" 例子 cat -n catalina.out | grep "abc
  • 如何利用trie树加快关键词查找

    千次阅读 2017-08-08 19:33:07
    项目中有如下需求,给定一个关键词库(规模不定,从几百到几千不等),需要在一句话或者一段内容中快速找出关键词,如果有任何一个关键词命中就可以直接返回。 1. 简单的方法就是依次判断每个词是否存在于给定内容...
  • std::find_if 今天发现自己写查找,或者排序,都...然后根据外面给定的关键词查找对应dd中符合匹配的key的数据,可能有一个,可能有多个 我的写法开始是死板的for循环匹配,如下: for(int i = 0 ;i<dd.len...
  • QQ群搜索软件 按关键词 按群号 自动搜集群信息 控制端控制 多台电脑同时进行
  • Python 实现的关键词查找小工具

    千次阅读 2016-08-11 17:08:09
    平时工作时,有时会遇到这样的情景:在一个目录及其子目录下所有的文本文件中查找某个关键字、词或者完整的句子。当然,如果是在Linux平台上,find+egrep就能实现这样的功能。不过最近学习了Python tkinter相关的...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 3,225
精华内容 1,290
关键字:

关键词查找