例句:
“胸部因呼吸困难而受到影响”
和
“呼吸困难影响胸部”
所需关系:
“呼吸困难 -> 胸部”
我通过查看句子的依存树尝试了依存匹配,但仍然无法实现关系。
您应该根据您的具体情况使用
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 的标记的关系。