即使词序发生变化,我如何能够一致地将一个单词映射到句子中的另一个单词,例如将症状映射到受影响的器官?

问题描述 投票:0回答:1

例句:

“胸部因呼吸困难而受到影响”

“呼吸困难影响胸部”

所需关系:

“呼吸困难 -> 胸部”

我通过查看句子的依存树尝试了依存匹配,但仍然无法实现关系。

nlp dependency-tree
1个回答
0
投票

您应该根据您的具体情况使用

Relation Extraction
技术
Casual Relation Extraction
。主要目标是识别检测到的实体/事件之间是否存在随意关系。 SpaCy 中的简单实现如下所示:

import spacy

# Load spaCy's transformer-based model
nlp = spacy.load("en_core_web_sm")

# Define a sample text for relationship extraction
text = "Chest is affected due to breathlessness"
# Process the text with spaCy
doc = nlp(text)

# Create a list to store extracted relationships
relationships = []

# Iterate through the sentences in the document
for sent in doc.sents:
    # Iterate through the named entities (people, organizations etc.) in the sentence
    for token in sent:
        if token.dep_ in ["attr", "nsubj", "dobj"]:
            relationships.append((ent.text, token.text))

for named_entities, relation in relationships:
    print(f"{named_entities} --> {relation}")

您可以根据您的特定上下文/问题进一步提取 NER 实体,并应用过滤器以确保仅分析您所需的 NER 的标记的关系。

© www.soinside.com 2019 - 2024. All rights reserved.