【问题标题】:term list / term vector pos-tagging in RR中的术语列表/术语向量后标记
【发布时间】:2018-05-14 14:42:04
【问题描述】:

我有一个 .csv 文件,其中只有一列包含 1000 行。每行包含一个词(词袋模型)。现在我想找出每个单词是否是名词、动词、形容词等。我想要第二列(有 1000 行),每列包含属于列中单词的信息(名词或动词) 1.

我已经将 csv 导入到 R 中。但是我现在需要做什么?

[这里是一个例子。我有这些词,我想知道它是否是名词动词等] [

【问题讨论】:

  • 请在帖子中添加示例,不要链接到第三方网站

标签: r pos-tagger term-vectors


【解决方案1】:

有多种选择,但您可以使用udpipe

terms <- data.frame(term = c("unit", "determine", "generate", "digital", "mount", "control", "position", "input", "output", "user"),
                    stringsAsFactors = FALSE)

library(udpipe)

# check if model is already downloaded. 
if (file.exists("english-ud-2.0-170801.udpipe")) 
  ud_model <- udpipe_load_model(file = "english-ud-2.0-170801.udpipe") else {
    ud_model <- udpipe_download_model(language = "english")
    ud_model <- udpipe_load_model(ud_model$file_model)
  }


# no need for parsing as this data only contains single words.
t <- udpipe_annotate(ud_model, terms$term, parser = "none")
t <- as.data.frame(t)
terms$POSTAG <- t$upos

terms
        term POSTAG
1       unit   NOUN
2  determine   VERB
3   generate   VERB
4    digital    ADJ
5      mount   NOUN
6    control   NOUN
7   position   NOUN
8      input   NOUN
9     output   NOUN
10      user   NOUN

【讨论】:

    【解决方案2】:

    您可以使用spacyr,它是Python 包spaCy 的R 包装器。

    注意:你将不得不

    library(spacyr)
    
    spacy_initialize(python_executable = '/path/to/python')
    

    那么根据你的条件:

    Terms <- data.frame(Term = c("unit",
                        "determine",
                        "generate",
                        "digital",
                        "mount",
                        "control",
                        "position",
                        "input",
                        "output",
                        "user"), stringsAsFactors = FALSE)
    

    使用函数spacy_parse() 标记您的术语并将它们添加到您的数据框:

    Terms$POS_TAG <- spacy_parse(Terms$Term)$pos
    

    结果是:

            Term POS_TAG
    1       unit    NOUN
    2  determine    VERB
    3   generate    VERB
    4    digital     ADJ
    5      mount    VERB
    6    control    NOUN
    7   position    NOUN
    8      input    NOUN
    9     output    NOUN
    10      user    NOUN
    

    【讨论】:

      猜你喜欢
      • 2014-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      相关资源
      最近更新 更多