Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Document' object has no attribute 'words' #85

Open
mashaonian opened this issue Sep 29, 2024 · 0 comments
Open

'Document' object has no attribute 'words' #85

mashaonian opened this issue Sep 29, 2024 · 0 comments

Comments

@mashaonian
Copy link

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
2 words = []
3 # skip the first two words, which header
----> 4 for word in sentence.words:
5 words.append(word.text)
6 print(" ".join(words)[:80] + "...")

File ~/papermage/papermage/magelib/entity.py:105, in Entity.getattr(self, name)
103 try:
104 if len(self.spans) > 0:
--> 105 intersection = self.intersect_by_span(name=name)
106 if len(intersection) == 0 and len(self.boxes) > 0:
107 intersection = self.intersect_by_box(name=name)

File ~/papermage/papermage/magelib/entity.py:124, in Entity.intersect_by_span(self, name)
121 if self.layer.doc is None:
122 raise ValueError("This Entity's Layer is not attached to a Document")
--> 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 def intersect_by_span(self, query: Entity, name: str) -> List[Entity]:
191 """Finds all entities that intersect with the query"""
--> 192 return self.get_layer(name=name).intersect_by_span(query=query)
...
69 def get_layer(self, name: str) -> Layer:
70 """Gets a layer by name. For example, doc.get_layer("sentences") returns sentences."""
---> 71 return getattr(self, name)

AttributeError: 'Document' object has no attribute 'words'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant