2016-12-16 1 views
2

색인 항목과 함께 텍스트 (예 : 생물학 텍스트의 경우 '스폰지 뼈')에서 텍스트에 나타나는 중요한 여러 단어 표현 (MWE)을 나타내는 텍스트가 있습니다. 이 항목을 사용하여 spaCy에서 사용자 지정 일치 프로그램을 구성하여 텍스트의 MWE 발생을 인식 할 수 있습니다. 추가 요구 사항은 MWE 구성 단어의 lemmatized 표현 및 POS 태그를 유지하려면 일치 항목을 필요로한다는 것입니다.Spacy의 다중 단어 표현 인식

비슷한 일을하는 기존의 spaCy 예제를 살펴 봤지만 패턴을 얻을 수없는 것 같습니다.

답변

-1

Spacy 문서는 여러 구와 함께 Matcher 클래스 사용시 명확하지 않지만 Github 레포에는 example과 일치하는 멀티 어구가 있습니다.

나는 최근에 똑같은 도전에 직면 해 있었고 아래와 같이 작업을했습니다. 내 텍스트 파일에는 한 줄에 하나의 레코드가 포함되어 있으며 구 및 설명은 '::'로 구분됩니다.

import spacy 
import io 
from spacy.matcher import PhraseMatcher 

nlp = spacy.load('en') 
text = nlp(u'Your text here') 
rules = list() 

# Create a list of tuple of phrase and description from the file 
with io.open('textfile','r',encoding='utf8') as doc: 
    rules = [tuple(line.rstrip('\n').split('::')) for line in doc] 

# convert the phrase string to a spacy doc object 
rules = [(nlp(item[0].lower()),item[-1]) for item in rules ] 

# create a dictionary for accessing value using the string as the index which is returned by matcher class 
rules_dict = dict() 
for key,val in rules: 
    rules_dict[key.text]=val 

# get just the phrases from rules list 
rules_phrases = [item[0] for item in rules] 

# match using the PhraseMatcher class 
matcher = PhraseMatcher(nlp.vocab,rules_phrases) 
matches = matcher(text) 
result = list() 

for start,end,tag,label,m in matches: 
    result.append({"start":start,"end":end,"phrase":label,"desc":rules_dict[label]}) 
print(result)