Python 在R Markdown中使用spacy与网状结构

Python 在R Markdown中使用spacy与网状结构,python,r,r-markdown,spacy,reticulate,Python,R,R Markdown,Spacy,Reticulate,我试图在R标记文档中使用spacy。除了使用displacy进行渲染外,其他一切似乎都正常。这是我正在使用的代码块: ```{python} from spacy import displacy doc = nlp("My name is Dhiraj.") displacy.render(doc) ``` 当我编写文档或者执行代码块时,我看不到带有箭头的svg。相反,这是执行上述代码块时的输出: '<svg xmlns="http://www.w3.org/2000/svg" xmln

我试图在R标记文档中使用
spacy
。除了使用
displacy
进行渲染外,其他一切似乎都正常。这是我正在使用的代码块:

```{python}
from spacy import displacy
doc = nlp("My name is Dhiraj.")
displacy.render(doc)
```
当我编写文档或者执行代码块时,我看不到带有箭头的svg。相反,这是执行上述代码块时的输出:

'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="127-0" class="displacy" width="750" height="224.5" style="max-width: none; height: 224.5px; color: #000000; background: #ffffff; font-family: Arial">\n<text class="displacy-token" fill="currentColor" text-anchor="middle" y="134.5">\n    <tspan class="displacy-word" fill="currentColor" x="50">My</tspan>\n    <tspan class="displacy-tag" dy="2em" fill="currentColor" x="50">ADJ</tspan>\n</text>\n\n<text class="displacy-token" fill="currentColor" text-anchor="middle" y="134.5">\n    <tspan class="displacy-word" fill="currentColor" x="225">name</tspan>\n    <tspan class="displacy-tag" dy="2em" fill="currentColor" x="225">NOUN</tspan>\n</text>\n\n<text class="displacy-token" fill="currentColor" text-anchor="middle" y="134.5">\n    <tspan class="displacy-word" fill="currentColor" x="400">is</tspan>\n    <tspan class="displacy-tag" dy="2em" fill="currentColor" x="400">VERB</tspan>\n</text>\n\n<text class="displacy-token" fill="currentColor" text-anchor="middle" y="134.5">\n    <tspan class="displacy-word" fill="currentColor" x="575">Dhiraj.</tspan>\n    <tspan class="displacy-tag" dy="2em" fill="currentColor" x="575">PROPN</tspan>\n</text>\n\n<g class="displacy-arrow">\n    <path class="displacy-arc" id="arrow-127-0-0" stroke-width="2px" d="M70,89.5 C70,2.0 225.0,2.0 225.0,89.5" fill="none" stroke="currentColor"/>\n    <text dy="1.25em" style="font-size: 0.8em; letter-spacing: 1px">\n        <textPath xlink:href="#arrow-127-0-0" class="displacy-label" startOffset="50%" fill="currentColor" text-anchor="middle">poss</textPath>\n    </text>\n    <path class="displacy-arrowhead" d="M70,91.5 L62,79.5 78,79.5" fill="currentColor"/>\n</g>\n\n<g class="displacy-arrow">\n    <path class="displacy-arc" id="arrow-127-0-1" stroke-width="2px" d="M245,89.5 C245,2.0 400.0,2.0 400.0,89.5" fill="none" stroke="currentColor"/>\n    <text dy="1.25em" style="font-size: 0.8em; letter-spacing: 1px">\n        <textPath xlink:href="#arrow-127-0-1" class="displacy-label" startOffset="50%" fill="currentColor" text-anchor="middle">nsubj</textPath>\n    </text>\n    <path class="displacy-arrowhead" d="M245,91.5 L237,79.5 253,79.5" fill="currentColor"/>\n</g>\n\n<g class="displacy-arrow">\n    <path class="displacy-arc" id="arrow-127-0-2" stroke-width="2px" d="M420,89.5 C420,2.0 575.0,2.0 575.0,89.5" fill="none" stroke="currentColor"/>\n    <text dy="1.25em" style="font-size: 0.8em; letter-spacing: 1px">\n        <textPath xlink:href="#arrow-127-0-2" class="displacy-label" startOffset="50%" fill="currentColor" text-anchor="middle">attr</textPath>\n    </text>\n    <path class="displacy-arrowhead" d="M575.0,91.5 L583.0,79.5 567.0,79.5" fill="currentColor"/>\n</g>\n</svg>'
'\n\n My\n ADJ\n\n\n\n name\n noon\n\n\n\n是动词\n\n\n\n Dhiraj。\n PROPN\n\n\n\n\n\n\n\n\n poss\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n

如何将其呈现为预期的svg?

假设您要输出到HTML,如果区块选项中有
results='asis'
,这应该可以工作,因此输出直接解释为HTML:

```{python, results='asis'}
import spacy
from spacy import displacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("My name is Dhiraj.")
displacy.render(doc)
```
我的工作标记文件的全部内容:

---
title: "Python test"
output: html_document
---

```{python, results='asis'}
import spacy
from spacy import displacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("My name is Dhiraj.")
displacy.render(doc)
```

谢谢,但即使添加了
results='asis'
,输出相同。未呈现svg。在YAML中,输出是
html\u文档
。升级到1.15版后没有乐趣。我使用Mac OS。这可能是个问题吗?非常感谢你的帮助!添加
results='asis'
后,我没有编织文档!我只是想执行代码块。我的错。但是现在当我编织它时,我看到了SVG。再次感谢您的帮助和耐心!