标签: n-gram

Mysql ngram 全文索引不适用于 utf8mb4_bin

我使用 utf8mb4_bin 作为标题列,所以我希望它是全文区分大小写的搜索。但实际上查询返回空。

CREATE TABLE `test_table` (
`id` int NOT NULL AUTO_INCREMENT,
`title` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `title` (`title`) WITH parser ngram) ENGINE=InnoDB AUTO_INCREMENT=173 DEFAULT
CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

INSERT INTO test_table value (NULL, 'Hello');

SELECT *
FROM test_table
WHERE match(title) against ('Hello' in boolean MODE) > 0; // return empty
Run Code Online (Sandbox Code Playgroud)

但如果我插入并查询“hello”,它会起作用,ngram 解析器是否会尝试小写来查询术语?

mysql full-text-search case-sensitive n-gram uppercase

7
推荐指数
0
解决办法
294
查看次数

使用java hashmap进行n-gram建模

我需要建模一组n-gram(n个单词的序列)及其上下文(n-gram附近出现的单词及其频率).我的想法是这样的:

public class Ngram {

    private String[] words;
    private HashMap<String, Integer> contextCount = new HashMap<String, Integer>();
}
Run Code Online (Sandbox Code Playgroud)

然后,对于所有不同的n-gram的计数,我使用另一个Hashmap,比如

HashMap<String, Ngram> ngrams = new HashMap<String, Ngram>();
Run Code Online (Sandbox Code Playgroud)

我在接收文本时添加它.问题是,当n-gram的数量超过10,000左右时,JVM Heap会填满(它设置为最大1.5GB),而且一切都变得非常糟糕.

有没有更好的方法来做到这一点,以避免这种内存消耗?此外,n-gram之间的上下文应该很容易比较,我不确定我的解决方案是否可行.

java string hashmap n-gram

6
推荐指数
1
解决办法
4600
查看次数

NLP算法"填写"搜索词

我正在尝试编写一种算法(我假设将依赖于自然语言处理技术)来"填写"搜索词列表.这种东西可能有一个我不知道的名字.这种问题叫什么,什么样的算法会给我以下行为?

输入:

    docs = [
    "I bought a ticket to the Dolphin Watching cruise",
    "I enjoyed the Dolphin Watching tour",
    "The Miami Dolphins lost again!",
    "It was good going to that Miami Dolphins game"
    ], 
    search_term = "Dolphin"
Run Code Online (Sandbox Code Playgroud)

输出:

["Dolphin Watching", "Miami Dolphins"]
Run Code Online (Sandbox Code Playgroud)

它基本上应该弄清楚,如果"Dolphin"出现,它实际上总是在"海豚观赏"或"迈阿密海豚"中.Python中的解决方案首选.

python nlp n-gram

6
推荐指数
1
解决办法
342
查看次数

Elasticsearch - EdgeNgram + highlight + term_vector =错误的亮点

当我使用带有edgengram的分析器(min = 3,max = 7,front)+ term_vector = with_positions_offsets

使用text ="CouchDB"的文档

当我搜索"couc"时

我的亮点是"cou"而不是"couc"


似乎我的亮点仅在于最小匹配令牌"cou",而我希望在准确的令牌上(如果可能)或至少找到最长的令牌.

它使用term_vector = with_positions_offsets分析文本时工作正常

删除term_vector = with_positions_offsets的性能有什么影响?

java lucene search n-gram elasticsearch

6
推荐指数
1
解决办法
3018
查看次数

NLTK可以轻松计算单词的重要性.信件怎么样?

我已经在网上看到大量关于python NLTK如何使计算bigrams单词变得容易的文档.

信件怎么样?

我想要做的是插入字典并让它告诉我不同​​字母对的相对频率.

最终,我想制作一些马尔可夫过程,以产生看起来很可能(但是假的)单词.

python nlp nltk n-gram

6
推荐指数
2
解决办法
2410
查看次数

python中TfidfVectorizer中n-gram的令牌模式

TfidfVectorizer是否使用python 正则表达式识别n-gram ?

在阅读scikit-learn TfidfVectorizer的文档时出现了这个问题,我看到在单词级别识别n-gram的模式是token_pattern=u'(?u)\b\w\w+\b'.我很难看到它是如何工作的.考虑bi-gram案例.如果我做:

    In [1]: import re
    In [2]: re.findall(u'(?u)\b\w\w+\b',u'this is a sentence! this is another one.')
    Out[2]: []
Run Code Online (Sandbox Code Playgroud)

我找不到任何双胞胎.鉴于:

    In [2]: re.findall(u'(?u)\w+ \w*',u'this is a sentence! this is another one.')
    Out[2]: [u'this is', u'a sentence', u'this is', u'another one']
Run Code Online (Sandbox Code Playgroud)

发现一些(但不是全部,例如u'is a',所有其他甚至计数的双字母都缺失).在解释\b字符函数时我做错了什么?

注意:根据正则表达式模块文档,re中\b字符应该是:

\ b匹配空字符串,但仅匹配单词的开头或结尾.单词被定义为字母数字或下划线字符的序列,因此单词的结尾由空格或非字母数字的非下划线字符表示.

我看到问题解决识别蟒蛇正克的问题(见1,2),所以次要的问题是:我应该这样做,我的文字喂养TfidfVectorizer前添加加入正克?

python regex n-gram scikit-learn

6
推荐指数
1
解决办法
2127
查看次数

克服Ashton String任务中的MemoryError/Slow Runtime

Ashton String任务中,目标是:

按字典顺序排列给定字符串的所有不同子串并将它们连接起来.打印连接字符串的第K个字符.确保K的给定值有效,即将存在第K个字符.

Input Format:

第一行将包含数字T即测试用例数.每个测试用例的第一行将包含一个包含字符(a-z)的字符串,第二行将包含一个数字K.

Output Format:

打印第K个字符(字符串为1索引)

而且Constraints

1≤:T≤5
1≤长度≤105
k将是一个适当的整数.

例如,给定输入:

1
dbac
3
Run Code Online (Sandbox Code Playgroud)

输出将是: c

我已尝试使用此代码完成任务,它适用于相对较短的字符串:

from itertools import chain

def zipngram(text, n=2):
    words = list(text)
    return zip(*[words[i:] for i in range(n)])

for _ in input():
    t = input()
    position = int(input())-1 # 0th indexing
    chargrams = chain(*[zipngram(t,i) for i in range(1,len(t)+1)])
    concatstr = ''.join(sorted([''.join(s) for s in chargrams]))
    print (concatstr[position])
Run Code Online (Sandbox Code Playgroud)

但是如果输入文件看起来像这样:http://pastebin.com/raw/WEi2p09H并且所需的输出是:

l
s …
Run Code Online (Sandbox Code Playgroud)

python string out-of-memory n-gram

6
推荐指数
1
解决办法
279
查看次数

使用tm和RWeka创建N-Grams - 与VCorpus合作但不与Corpus合作

在使用'tm'和'RWeka'软件包创建biGrams的许多指南之后,我感到很沮丧的是,在tdm中只返回了1克.通过大量的反复试验,我发现使用' VCorpus '但不使用' Corpus ' 可以实现正常的功能.顺便说一句,我很确定这是在1个月前与'Corpus'合作但现在不是.

R(3.3.3),RTools(3.4),RStudio(1.0.136)和所有软件包(tm 0.7-1,RWeka 0.4-31)已更新至最新版本.

如果对于语料库不起作用以及其他人是否有同样的问题,我将不胜感激.

#A Reproducible example
#
#Weka bi-gram test
#

library(tm)
library(RWeka)

someCleanText <- c("Congress shall make no law respecting an establishment of",
                    "religion, or prohibiting the free exercise thereof or",
                    "abridging the freedom of speech or of the press or the",
                    "right of the people peaceably to assemble and to petition",
                    "the Government for a redress of grievances")

aCorpus <- Corpus(VectorSource(someCleanText))   #With this, only 1-Grams …
Run Code Online (Sandbox Code Playgroud)

r n-gram tm term-document-matrix rweka

6
推荐指数
1
解决办法
3036
查看次数

ElasticSearch Edge NGram vs Prefix查询

假设我们有一个相对较短的文本字段,假设最多10个字符并保存为关键字.
我希望我的用户能够前缀搜索这个字段(不是自动完成/搜索你的类型).
我已经阅读过Elastic的文档,前缀查询的扩展性很差,并且它们提供了几个示例来演示它.

什么时候可以使用前缀搜索,什么时候应该使用index-time edge-ngrams?构建和存储此字段的索引时间edge-ngrams听起来过多,但也许我错过了一些东西.

prefix n-gram elasticsearch

6
推荐指数
1
解决办法
548
查看次数

如何获得句子文本中二元组的概率?

我有一个包含很多句子的文本。我如何使用nltk.ngrams它来处理它?

这是我的代码:

   sequence = nltk.tokenize.word_tokenize(raw) 
   bigram = ngrams(sequence,2)
   freq_dist = nltk.FreqDist(bigram)
   prob_dist = nltk.MLEProbDist(freq_dist)
   number_of_bigrams = freq_dist.N()
Run Code Online (Sandbox Code Playgroud)

但是,上面的代码假设所有句子都是一个序列。但是,句子是分开的,我猜一个句子的最后一个词与另一个句子的起始词无关。如何bigram为这样的文本创建一个?我还需要prob_dist并且number_of_bigrams基于`freq_dist。

有类似这样的问题什么是 ngram 计数以及如何使用 nltk 实现?但它们主要是关于一个单词序列。

python nltk n-gram python-3.x

6
推荐指数
1
解决办法
5472
查看次数