标签: text-mining

挖掘Wikipedia用于文本挖掘的映射关系

我计划开发一个基于Web的应用程序,它可以抓取维基百科来查找关系并将其存储在数据库中.通过关系,我的意思是搜索一个名字,比如'比尔盖茨'并找到他的页面,下载它并从页面中提取各种信息并将其存储在数据库中.信息可能包括他的出生日期,他的公司和其他一些事情.但我需要知道是否有任何方法可以从页面中找到这些唯一数据,以便我可以将它们存储在数据库中.任何特定的书籍或算法将不胜感激.还提到好的开源库会很有帮助.

谢谢

python wikipedia data-mining pattern-matching text-mining

2
推荐指数
1
解决办法
2878
查看次数

VIM:如何搜索匹配没有特定字符的行?

我有一些来自ldiff文件的这样的行,

dn: cn=dkalland_directs_ww,cn=org_groups,cn=beehive_groups,cn=groups,dc=oracle
,dc=com
businesscategory: open
cn: dkalland_directs_ww
description: Directs Group for daniel.kallander@oracle.com
displayname: dkalland_directs_ww
mail: dkalland_directs_ww@oracle.com
objectclass: top
objectclass: orclGroup
objectclass: groupOfUniqueNames
orclglobalid: modified
orclnormdn: cn=dkalland_directs_ww,cn=org_groups,cn=beehive_groups,cn=groups,d
c=oracle,dc=com
owner: cn=BHGRPADMIN_WW,L=AMER,DC=ORACLE,DC=COM
uniquemember: cn=mattias_tobiasson,dc=us,dc=oracle,dc=com
uniquemember: cn=mattias_joelson,dc=us,dc=oracle,dc=com
uniquemember: cn=markus_persson,dc=us,dc=oracle,dc=com 
...
Run Code Online (Sandbox Code Playgroud)

现在因为有一些行是前一行的延续.我想加入他们各自的路线.

我感到困惑的是如何在没有":"角色的情况下搜索一条线,以便我可以将它与前一行连接起来.

Plz的帮助.

vi vim search design-patterns text-mining

2
推荐指数
1
解决办法
2035
查看次数

如何在对话中总结每个人的字数?


我开始学习Python,我正在尝试编写一个导入文本文件的程序,计算单词总数,计算特定段落中的单词数(由每个参与者表示,由'P1'描述) ,'P2'等),从我的单词计数中排除这些单词(即'P1'等),并分别打印段落.

感谢@James Hurford我得到了这段代码:

words = None
with open('data.txt') as f:
   words = f.read().split()
total_words = len(words)
print 'Total words:', total_words

in_para = False
para_type = None
paragraph = list()
for word in words:
  if ('P1' in word or
      'P2' in word or
      'P3' in word ):
      if in_para == False:
         in_para = True
         para_type = word
      else:
         print 'Words in paragraph', para_type, ':', len(paragraph)
         print ' '.join(paragraph)
         del paragraph[:]
         para_type = word
  else:
    paragraph.append(word)
else:
  if in_para == True: …
Run Code Online (Sandbox Code Playgroud)

python nlp sum count text-mining

2
推荐指数
1
解决办法
1332
查看次数

在R中查找多个术语的findAssocs

在RI中,用于[tm package][1]从文档集构建术语 - 文档矩阵.

我的目标是从术语文档矩阵中的所有双字母组合中提取单词关联,并为每个前三个或一些返回.因此,我正在寻找一个包含矩阵中所有ro​​w.names的变量,以便该函数findAssocs()可以完成他的工作.

到目前为止这是我的代码:

library(tm)
library(RWeka)
txtData <- read.csv("file.csv", header = T, sep = ",")
txtCorpus <- Corpus(VectorSource(txtData$text))

...further preprocessing

#Tokenizer for n-grams and passed on to the term-document matrix constructor
BigramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 2, max = 2))
txtTdmBi <- TermDocumentMatrix(txtCorpus, control = list(tokenize = BigramTokenizer))

#term argument holds two words since the BigramTokenizer extracted all pairs from txtCorpus
findAssocs(txtTdmBi, "cat shop", 0.5)
cat cabi  cat scratch  ...
    0.96 …
Run Code Online (Sandbox Code Playgroud)

r text-mining term-document-matrix

2
推荐指数
1
解决办法
7879
查看次数

R:使用strsplit和perl REGEX语法提取大写字母和特殊字符

你如何只提取/以下大写字母和整个字母[[:punct:]]/$[[:punct:]].

text <- c("This/ART ,/$; Is/NN something something/else A/VAFIN faulty/ADV text/ADV which/ADJD i/PWS propose/ADV as/APPR Example/NE ./$. So/NE It/PTKNEG makes/ADJD no/VAFIN sense/ADV at/KOUS all/PDAT ,/$, it/APPR Has/ADJA Errors/NN  ,/$; and/APPR it/APPR is/CARD senseless/NN again/ART ./$:")

# HOW to?
textPOS <- strsplit(text,"(   )|(?<=[[:punct:]]/\\$[[:punct:]])", perl=TRUE)
#                          ^^^ 
#                         extract only the "/" with the following capital letters
#                         and the whole "[[:punct:]]/$[[:punct:]]"

# Expected RETURN:
> textPOS
[1] "/ART" ",/$;" "/NN" "/VAFIN" "/ADV" "/ADV" "/ADJD" "/PWS" "/ADV" "/APPR" …
Run Code Online (Sandbox Code Playgroud)

regex r text-mining strsplit

2
推荐指数
1
解决办法
2550
查看次数

使用inspect()函数发生R错误

我的目标是应用文本挖掘的关联规则.

我有这个字符串样本:

sample.word = c("abstracting","abstracting workflow","access control","access information","access methods","access patterns","access permissions","access to government information","accountability","acetamides")
Run Code Online (Sandbox Code Playgroud)

比我制作一个所有值为0的矩阵

incidence.matrix_sample <- matrix(0, nrow=5, ncol=length(sample.word))
Run Code Online (Sandbox Code Playgroud)

我添加字符串作为矩阵列

colnames(incidence.matrix_sample) <- sample.word
Run Code Online (Sandbox Code Playgroud)

现在我在使用pmatch函数出现在文档中的术语列中放入1个值(documents.ids [[i]]是一个id为文档的向量)

for(i in 1:(dim(incidence.matrix_sample)[1]))
{
  incidence.matrix_sample[i, pmatch(documents.ids[[i]], sample.word)] <- 1
}
Run Code Online (Sandbox Code Playgroud)

我尝试继续将矩阵转换为itemMatrix,然后作为事务(使用as(my.matrix,"transactions")函数)但是当我尝试检查规则时,我得到相同的错误:

incidence.matrix_sample <- as(incidence.matrix_sample, "itemMatrix")
incidence.matrix_sample <- as(incidence.matrix_sample, "transactions")
inspect(incidence.matrix_sample)
Run Code Online (Sandbox Code Playgroud)

结果是:

Errore in UseMethod("inspect", x) : 
  no applicable method for 'inspect' applied to an object of class "c('matrix', 'double', 'numeric')"
Run Code Online (Sandbox Code Playgroud)

以及使用先验函数进行入射的相同问题.matrix_sample

Errore in UseMethod("inspect", x) : 
  no applicable method for 'inspect' applied to an …
Run Code Online (Sandbox Code Playgroud)

r matrix text-mining arules

2
推荐指数
1
解决办法
5829
查看次数

R中列表的which()函数

这应该很容易,但是我希望找出如何返回包含一个元素的列表的索引。例如,在下面的列表中,假设我要查找所有以“ a”为元素的索引。我想要一个函数返回索引1。

> x = list(c("a", "b"), "c")

> x
[[1]]
[1] "a" "b"

[[2]]
[1] "c"

> which(x=="a")

integer(0)
Run Code Online (Sandbox Code Playgroud)

当然,which()在这里不起作用。任何帮助,将不胜感激!

r text-mining

2
推荐指数
1
解决办法
2071
查看次数

使用R中的文本分类和大稀疏矩阵

我正在研究一个文本多类分类项目,我需要构建文档/术语矩阵,并用R语言进行训练和测试.

我已经有了不适合R中基矩阵的有限维度的数据集,并且需要构建大的稀疏矩阵才能对例如100k的推文进行分类.我正在使用quanteda软件包,因为它现在比包tm更有用和可靠,其中使用字典创建DocumentTermMatrix,使得过程难以置信地使用小数据集.目前,正如我所说的,我使用quanteda来构建等效的Document Term Matrix容器,稍后我将其转换为data.frame来执行培训.

我想知道是否有办法建立这么大的矩阵.我一直在阅读有关的bigmemory包,允许这种容器的,但我不知道它会与插入符号为后来的分类.总的来说,我想了解这个问题并构建一个解决方法,以便能够处理更大的数据集,因为RAM不是(大)问题(32GB),但我正试图找到一种方法来做到这一点,我觉得完全失去了关于它.

r classification text-mining r-caret quanteda

2
推荐指数
1
解决办法
1210
查看次数

整洁的文本格式内的单词替换

嗨,我正在使用tidy_text格式,我试图将字符串"电子邮件"和"电子邮件"替换为"电子邮件".

set.seed(123)
terms <- c("emails are nice", "emailing is fun", "computer freaks", "broken modem")
df <- data.frame(sentence = sample(terms, 100, replace = TRUE))
df
str(df)
df$sentence <- as.character(df$sentence)
tidy_df <- df %>% 
unnest_tokens(word, sentence)

tidy_df %>% 
count(word, sort = TRUE) %>% 
filter( n > 20) %>% 
mutate(word = reorder(word, n)) %>% 
ggplot(aes(word, n)) +
geom_col() +
xlab(NULL) + 
coord_flip()
Run Code Online (Sandbox Code Playgroud)

这工作正常,但当我使用:

 tidy_df <- gsub("emailing", "email", tidy_df)
Run Code Online (Sandbox Code Playgroud)

替换单词并再次运行条形图我收到以下错误消息:

UseMethod("group_by_")中的错误:没有适用于"group_by_"的方法应用于类"character"的对象

有没有人知道如何在不改变tidy_text的结构/类的情况下,在整洁的文本格式中轻松替换单词?

r text-mining tidytext

2
推荐指数
1
解决办法
2636
查看次数

使用GoogleFinanceSource函数使用tm.plugin.webmining包进行文本挖掘

我正在网上书http://tidytextmining.com/上学习文本挖掘.在第五章:http: //tidytextmining.com/dtm.html#financial

以下代码:

library(tm.plugin.webmining)
library(purrr)

company <- c("Microsoft", "Apple", "Google", "Amazon", "Facebook",
             "Twitter", "IBM", "Yahoo", "Netflix")
symbol <- c("MSFT", "AAPL", "GOOG", "AMZN", "FB", "TWTR", "IBM", "YHOO", "NFLX")

download_articles <- function(symbol) {
    WebCorpus(GoogleFinanceSource(paste0("NASDAQ:", symbol)))
}
stock_articles <- data_frame(company = company,
                             symbol = symbol) %>%
    mutate(corpus = map(symbol, download_articles))
Run Code Online (Sandbox Code Playgroud)

给我错误:

StartTag: invalid element name
Extra content at the end of the document
Error: 1: StartTag: invalid element name
2: Extra content at the end of the document
Run Code Online (Sandbox Code Playgroud)

任何提示?有人建议删除与"Twitter"相关的公司和符号,但它仍然不起作用并返回相同的错误.提前谢谢了

r text-mining tm

2
推荐指数
1
解决办法
1006
查看次数