'Document' object has no attribute 'words'
- Dominant language
- Python
- Stars
- 802
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Description
How to resolve the issue 'Document' object has no attribute 'words'?
for sentence in doc.abstracts[0].sentences:
words = []
# skip the first two words, which header
for word in sentence.words:
words.append(word.text)
print(" ".join(words)[:80] + "...")
AttributeError Traceback (most recent call last)
Cell In[9], [line 4](vscode-notebook-cell:?execution_count=9&line=4)
[2](vscode-notebook-cell:?execution_count=9&line=2) words = []
[3](vscode-notebook-cell:?execution_count=9&line=3) # skip the first two words, which header
----> [4](vscode-notebook-cell:?execution_count=9&line=4) for word in sentence.words:
[5](vscode-notebook-cell:?execution_count=9&line=5) words.append(word.text)
[6](vscode-notebook-cell:?execution_count=9&line=6) print(" ".join(words)[:80] + "...")
File ~/papermage/papermage/magelib/entity.py:105, in Entity.__getattr__(self, name)
[103](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/entity.py:103) try:
[104](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/entity.py:104) if len(self.spans) > 0:
--> [105](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/entity.py:105) intersection = self.intersect_by_span(name=name)
[106](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/entity.py:106) if len(intersection) == 0 and len(self.boxes) > 0:
[107](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/entity.py:107) intersection = self.intersect_by_box(name=name)
File ~/papermage/papermage/magelib/entity.py:124, in Entity.intersect_by_span(self, name)
[121](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/entity.py:121) if self.layer.doc is None:
[122](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/entity.py:122) raise ValueError("This Entity's Layer is not attached to a Document")
--> [124](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/entity.py:124) return self.layer.doc.intersect_by_span(query=self, name=name)
File ~/papermage/papermage/magelib/document.py:192, in Document.intersect_by_span(self, query, name)
[190](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/document.py:190) def intersect_by_span(self, query: Entity, name: str) -> List[Entity]:
[191](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/document.py:191) """Finds all entities that intersect with the query"""
--> [192](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/document.py:192) return self.get_layer(name=name).intersect_by_span(query=query)
...
[69](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/document.py:69) def get_layer(self, name: str) -> Layer:
[70](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/document.py:70) """Gets a layer by name. For example, `doc.get_layer("sentences")` returns sentences."""
---> [71](https://vscode-remote+wsl-002bubuntu-002d20-002e04.vscode-resource.vscode-cdn.net/home/kxcr/papermage/examples/~/papermage/papermage/magelib/document.py:71) return getattr(self, name)
AttributeError: 'Document' object has no attribute 'words'
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.