wowool-common 3.0.2.dev19__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of wowool-common might be problematic. Click here for more details.

Files changed (55) hide show
  1. wowool/analysis.py +289 -0
  2. wowool/analysis_parser.py +102 -0
  3. wowool/annotation/__init__.py +4 -0
  4. wowool/annotation/annotation.py +156 -0
  5. wowool/annotation/concept.py +473 -0
  6. wowool/annotation/paragraph.py +166 -0
  7. wowool/annotation/sentence.py +262 -0
  8. wowool/annotation/token.py +266 -0
  9. wowool/apps/info.py +97 -0
  10. wowool/common/pipeline/__init__.py +1 -0
  11. wowool/common/pipeline/objects.py +45 -0
  12. wowool/common/utilities.py +13 -0
  13. wowool/config.py +67 -0
  14. wowool/diagnostic.py +250 -0
  15. wowool/document/__init__.py +2 -0
  16. wowool/document/apps/chunks.py +22 -0
  17. wowool/document/apps/themes.py +11 -0
  18. wowool/document/apps/topics.py +11 -0
  19. wowool/document/document.py +399 -0
  20. wowool/document/factory.py +176 -0
  21. wowool/error.py +2 -0
  22. wowool/io/console/__init__.py +1 -0
  23. wowool/io/console/argument_parser.py +29 -0
  24. wowool/io/console/console.py +102 -0
  25. wowool/io/provider/__init__.py +4 -0
  26. wowool/io/provider/docx.py +26 -0
  27. wowool/io/provider/factory.py +173 -0
  28. wowool/io/provider/file.py +85 -0
  29. wowool/io/provider/html.py +42 -0
  30. wowool/io/provider/html_v2.py +420 -0
  31. wowool/io/provider/input_provider.py +38 -0
  32. wowool/io/provider/pdf.py +320 -0
  33. wowool/io/provider/pdf_no_layout.py +48 -0
  34. wowool/io/provider/rtf.py +14 -0
  35. wowool/io/provider/str.py +17 -0
  36. wowool/string/__init__.py +153 -0
  37. wowool/tool/woc/create.py +42 -0
  38. wowool/utility/__init__.py +16 -0
  39. wowool/utility/apps/decorators.py +66 -0
  40. wowool/utility/apps/yml_include.py +30 -0
  41. wowool/utility/csv/__init__.py +26 -0
  42. wowool/utility/default_arguments.py +44 -0
  43. wowool/utility/diagnostics.py +24 -0
  44. wowool/utility/iterators/__init__.py +59 -0
  45. wowool/utility/method_registry.py +20 -0
  46. wowool/utility/numbers.py +42 -0
  47. wowool/utility/path/__init__.py +1 -0
  48. wowool/utility/path/path.py +11 -0
  49. wowool/utility/text/cleanup.py +82 -0
  50. wowool/visitor.py +48 -0
  51. wowool/wow.py +424 -0
  52. wowool_common-3.0.2.dev19.dist-info/METADATA +10 -0
  53. wowool_common-3.0.2.dev19.dist-info/RECORD +55 -0
  54. wowool_common-3.0.2.dev19.dist-info/WHEEL +5 -0
  55. wowool_common-3.0.2.dev19.dist-info/top_level.txt +1 -0
@@ -0,0 +1,473 @@
1
+ from __future__ import annotations
2
+ from wowool.annotation.annotation import Annotation, ErrorAnnotationNotFound
3
+ from wowool.annotation.token import Token
4
+ from typing import Callable, Union, List, Type, cast, Generator, NewType, Iterator, Self
5
+
6
+
7
+ def _align(idx, collection) -> int:
8
+ bo = collection[idx].begin_offset
9
+ eo = collection[idx].end_offset
10
+ rvidx = idx - 1
11
+ while rvidx >= 0:
12
+ if bo == collection[rvidx].begin_offset and eo == collection[rvidx].end_offset:
13
+ rvidx -= 1
14
+ else:
15
+ return rvidx + 1
16
+ return idx
17
+
18
+
19
+ def _filter_pass_thru(concept) -> bool:
20
+ return True
21
+
22
+
23
+ class Concept(Annotation):
24
+ """
25
+ :class:`Concept` is a class that contains all the information of a concept
26
+ """
27
+
28
+ FilterType = Callable[[Self], bool]
29
+
30
+ def __init__(self, begin_offset: int, end_offset: int, uri: str):
31
+ """
32
+ Initialize a :class:`Concept` instance
33
+
34
+ :param begin_offset: Begin offset of the concept
35
+ :type begin_offset: ``int``
36
+ :param end_offset: End offset of the concept
37
+ :type end_offset: ``int``
38
+ :param uri: URI, or name, of the concept
39
+ :type uri: ``str``
40
+
41
+ :return: An initialized concept
42
+ :rtype: :class:`Concept`
43
+ """
44
+ self._attributes = {}
45
+ super(Concept, self).__init__(begin_offset, end_offset)
46
+ self._uri = uri
47
+ self._sentence_annotations = None
48
+ self._annotations = None
49
+ self._literals = None
50
+ self._stems = None
51
+ self._tokens = None
52
+ self._dict = None
53
+ self._canonical = None
54
+ self._text = None
55
+
56
+ @property
57
+ def uri(self) -> str:
58
+ """
59
+ :return: The URI, or name, of the concept
60
+ :type: ``str``
61
+ """
62
+ return self._uri
63
+
64
+ @property
65
+ def literal(self) -> str:
66
+ """
67
+ :return: The literal representation of the concept
68
+ :rtype: ``str``
69
+ """
70
+ return self.text
71
+
72
+ @property
73
+ def literals(self) -> List[str]:
74
+ """
75
+ :return: The literals of the concept
76
+ :rtype: A ``list`` of ``str``
77
+ """
78
+ if not self._literals:
79
+ self._literals = [token.literal for token in self.tokens]
80
+ return self._literals
81
+
82
+ @property
83
+ def stem(self) -> str:
84
+ """
85
+ :return: The stem representation of the concept
86
+ :type: ``str``
87
+ """
88
+ return " ".join(self.stems)
89
+
90
+ def has_canonical(self) -> bool:
91
+ if "canonical" in self._attributes:
92
+ return True
93
+ elif "icanonical" in self._attributes:
94
+ return True
95
+ return False
96
+
97
+ def _get_canonical(self) -> str:
98
+ if "canonical" in self._attributes:
99
+ return self._attributes["canonical"][0]
100
+ elif "icanonical" in self._attributes:
101
+ return self._attributes["icanonical"][0]
102
+ elif self._has_guesses() or self._has_props():
103
+ return self.literal
104
+ return self.stem if self.stem else self.literal
105
+
106
+ @property
107
+ def canonical(self) -> str:
108
+ """
109
+ :return: The stem representation of the concept
110
+ :type: ``str``
111
+ """
112
+ if self._canonical is None:
113
+ self._canonical = self._get_canonical()
114
+ return self._canonical
115
+
116
+ @property
117
+ def attributes(self):
118
+ return self._attributes
119
+
120
+ @property
121
+ def stems(self) -> List[str]:
122
+ """
123
+ :return: The stems of the concept
124
+ :rtype: A ``list`` of ``str``
125
+ """
126
+ if not self._stems:
127
+ self._stems = [token.stem for token in self.tokens]
128
+ return self._stems
129
+
130
+ def _get_text(self):
131
+ """
132
+ :return: A string representation of the concept
133
+ :rtype: ``str``
134
+ """
135
+ retval = ""
136
+ prev_tk = None
137
+ for tk in [a for a in self.annotations if a.is_token]:
138
+ if prev_tk and prev_tk.end_offset != tk.begin_offset:
139
+ retval += " "
140
+ retval += tk.literal
141
+ prev_tk = tk
142
+ return retval.strip()
143
+
144
+ @property
145
+ def text(self):
146
+ """
147
+ :return: A string representation of the concept
148
+ :rtype: ``str``
149
+ """
150
+ if self._text is None:
151
+ self._text = self._get_text()
152
+ return self._text
153
+
154
+ @property
155
+ def tokens(self) -> List[Token]:
156
+ """
157
+ :return: The tokens of the concept
158
+ :rtype: A ``list`` of ``str``
159
+ """
160
+ if not self._tokens:
161
+ assert self._sentence_annotations is not None
162
+ self._tokens = [
163
+ annotation
164
+ for annotation in self._sentence_annotations[self._annotation_idx :]
165
+ if annotation.is_token and annotation.begin_offset < self.end_offset
166
+ ]
167
+ return self._tokens
168
+
169
+ @property
170
+ def annotations(self) -> List[Annotation]:
171
+ """
172
+ :return: The tokens of the concept
173
+ :rtype: A ``list`` of ``str``
174
+ """
175
+ if not self._annotations:
176
+ assert self._sentence_annotations is not None
177
+ self._annotations = [
178
+ annotation for annotation in self._sentence_annotations[self._annotation_idx :] if annotation.begin_offset < self.end_offset
179
+ ]
180
+ return self._annotations
181
+
182
+ def set_attributes(self, new_attributes: dict):
183
+ self._attributes = new_attributes
184
+
185
+ def _has_guesses(self) -> bool:
186
+ return len([tk for tk in self.tokens if "guess" in tk.properties]) > 0
187
+
188
+ def _has_props(self) -> bool:
189
+ for tk in self.tokens:
190
+ if tk.has_pos("Prop"):
191
+ return True
192
+ return False
193
+
194
+ def __setstate__(self, d):
195
+ self.__dict__.update(d)
196
+
197
+ def __getstate__(self):
198
+ return self.__dict__
199
+
200
+ def __getattr__(self, name: str) -> Union[None, str, Concept]:
201
+ """
202
+ Find an attribute or the first child instance of the concept with the given name. Some often used attributes are:
203
+
204
+ * ``canonical``: canonical representation (``str``) of the concept
205
+ * ``attributes``: attributes (``dict``) collected on the concept
206
+
207
+ For example:
208
+
209
+ .. code-block:: python
210
+
211
+ # Find a child concept in this concept
212
+ person = concept.Person
213
+ # or print the attribute 'gender'
214
+ print(person.gender)
215
+
216
+ :param name: Attribute name
217
+ :type name: ``str``
218
+
219
+ :return: The first instance of the matching concept or the requested attribute value
220
+ :type: :class:`Concept` or ``str``
221
+ """
222
+
223
+ if name in self._attributes:
224
+ return ",".join(self._attributes[name])
225
+ concept = self.find_first(name)
226
+ if concept:
227
+ return cast(Concept, concept)
228
+
229
+ def find_first(self, uri: str) -> Union[None, Concept]:
230
+ """
231
+ Find the first child instance of the concept with the given URI in this concept
232
+
233
+ For example:
234
+
235
+ .. code-block:: python
236
+
237
+ # Find a child concept in the current concept
238
+ person = concept.find_first('Person'))
239
+
240
+ :param uri: URI, or name, of the concept
241
+ :type uri: ``str``
242
+
243
+ :returns: The first matching child instance of the given concept
244
+ :rtype: :class:`Concept`
245
+ """
246
+ try:
247
+ return next(self._find(uri))
248
+ except StopIteration:
249
+ return None
250
+
251
+ def find(self, uri: str) -> List[Concept]:
252
+ """
253
+ Find all child concepts with the given URI in this concept
254
+
255
+ For example:
256
+
257
+ .. code-block:: python
258
+
259
+ # Find a child concept in the current concept
260
+ for person in concept.find('Person')):
261
+ print(person)
262
+
263
+ :param uri: URI, or name, of the concept
264
+ :type uri: str
265
+
266
+ :returns: The matching child instances of the given concept
267
+ :rtype: A ``list`` of :class:`Concept`
268
+ """
269
+ return [concept for concept in self._find(uri)]
270
+
271
+ def _find(self, uri: str) -> Generator[Concept, None, None]:
272
+ assert self._sentence_annotations is not None
273
+ idx = _align(self._annotation_idx, self._sentence_annotations)
274
+ sent_len = len(self._sentence_annotations)
275
+ while idx < sent_len:
276
+ annotation = self._sentence_annotations[idx]
277
+ if annotation.is_concept and uri == cast(Concept, annotation).uri:
278
+ yield cast(Concept, annotation)
279
+ elif annotation.is_token:
280
+ if annotation.begin_offset < self.end_offset:
281
+ pass
282
+ else:
283
+ return
284
+ idx += 1
285
+
286
+ def match(self, call_able: Callable[[str], bool]) -> List[Concept]:
287
+ """
288
+ Find all child concepts with the given URI in this concept
289
+
290
+ For example:
291
+
292
+ .. code-block:: python
293
+
294
+ # Find a child concept in the current concept
295
+ for person in concept.find('Person')):
296
+ print(person)
297
+
298
+ :param uri: URI, or name, of the concept
299
+ :type uri: str
300
+
301
+ :returns: The matching child instances of the given concept
302
+ :rtype: A ``list`` of :class:`Concept`
303
+ """
304
+ return [concept for concept in self._match(call_able)]
305
+
306
+ def _match(self, call_able: Callable[[str], bool]) -> Generator[Concept, None, None]:
307
+ assert self._sentence_annotations is not None
308
+ idx = _align(self._annotation_idx, self._sentence_annotations)
309
+ sent_len = len(self._sentence_annotations)
310
+ while idx < sent_len:
311
+ annotation = self._sentence_annotations[idx]
312
+ if annotation.is_concept and call_able(cast(Self, annotation).uri):
313
+ yield cast(Concept, annotation)
314
+ elif annotation.is_token:
315
+ if annotation.begin_offset < self.end_offset:
316
+ pass
317
+ else:
318
+ return
319
+ idx += 1
320
+
321
+ def __getitem__(self, key):
322
+ """
323
+ :return: Attribute of the concept
324
+ :rtype: ``str``
325
+ """
326
+ if self._dict and key in self._dict:
327
+ return self._dict[key]
328
+
329
+ def rich(self) -> str:
330
+ """
331
+ :return: A rich string representation of the concept
332
+ :rtype: ``str``
333
+ """
334
+ retval = "<uri>C</uri>:" + Annotation.__repr__(self) + ": <uri>" + self.uri + "</uri>"
335
+ if self._attributes:
336
+ retval += ",@(<default>"
337
+ for k, vs in sorted(self._attributes.items()):
338
+ for v in vs:
339
+ retval += f"{k}='{v}' "
340
+ retval += "</default>)"
341
+ return retval
342
+
343
+ def keys(self):
344
+ """
345
+ This function is used to convert a concept object to a dictionary
346
+
347
+ .. code-block:: python
348
+
349
+ { **concept }
350
+
351
+
352
+ :return: a list of the keys of the concept.
353
+ :rtype: list(str)
354
+
355
+
356
+ """
357
+ if not self._dict:
358
+ self._dict = self.to_json()
359
+ return self._dict.keys()
360
+
361
+ def __repr__(self) -> str:
362
+ retval = "C:" + Annotation.__repr__(self) + ": " + self.uri
363
+ if self._attributes:
364
+ retval += ",@("
365
+ for k, vs in sorted(self._attributes.items()):
366
+ for v in vs:
367
+ retval += f"{k}='{v}' "
368
+ retval += ")"
369
+ return retval
370
+
371
+ def to_json(self):
372
+ """
373
+ :return: A dictionary representing a JSON object of the concept
374
+ :rtype: ``dict``
375
+ """
376
+ dict_self = {"uri": self.uri, "literal": self.literal, "stem": self.stem}
377
+ dict_attributes = {}
378
+ for k, vl in self._attributes.items():
379
+ dict_attributes[k] = ",".join([str(v) for v in vl])
380
+ return {**dict_self, **dict_attributes}
381
+
382
+ @staticmethod
383
+ def _document_iter(doc, filter: FilterType = _filter_pass_thru) -> Iterator[Concept]:
384
+ for sentence in doc:
385
+ for annotation in sentence:
386
+ if annotation.is_concept and filter(annotation):
387
+ yield annotation
388
+
389
+ @staticmethod
390
+ def _sentence_iter(sentence, filter: FilterType = _filter_pass_thru) -> Iterator[Concept]:
391
+ for annotation in sentence:
392
+ if annotation.is_concept and filter(annotation):
393
+ yield annotation
394
+
395
+ @staticmethod
396
+ def _concept_iter(concept, filter: FilterType = _filter_pass_thru, align: bool = True) -> Iterator[Concept]:
397
+ idx = _align(concept._annotation_idx, concept._sentence_annotations) if align else concept._annotation_idx + 1
398
+ N = len(concept._sentence_annotations)
399
+ while idx < N:
400
+ if concept._annotation_idx != idx:
401
+ annotation = concept._sentence_annotations[idx]
402
+ if annotation.begin_offset >= concept.end_offset:
403
+ break
404
+ if annotation.is_concept and filter(annotation) and annotation.end_offset <= concept.end_offset:
405
+ yield cast(Concept, annotation)
406
+ idx += 1
407
+
408
+ @staticmethod
409
+ def iter(object, filter: FilterType = _filter_pass_thru, align: bool = True) -> Iterator[Concept]:
410
+ """
411
+ Iterate over the concepts in a document, an analysis, a sentence or a concept. For example:
412
+
413
+ .. code-block:: python
414
+
415
+ document = analyzer("Hello from Antwerp, said John Smith.")
416
+ for concept in Concept.iter(document, lambda concept : concept.uri == "NP"):
417
+ print(concept)
418
+
419
+ :param object: Object to iterate
420
+ :type object: :class:`Analysis <wowool.analysis.Analysis>`, :class:`Sentence <wowool.annotation.sentence.Sentence>` or :class:`Concept <wowool.annotation.concept.Concept>`
421
+ :param filter: Predicate function to filter the concepts, callable that accepts a concept and returns True if the concept is considered a match
422
+ :type filter: Callable accepting a :class:`Concept` and returning a ``bool``
423
+
424
+ :return: A generator expression yielding concepts
425
+ :rtype: :class:`Concept <wowool.annotation.concept.Concept>`
426
+ """
427
+ from wowool.document.document import Document
428
+ from wowool.analysis import Analysis
429
+ from wowool.annotation import Sentence
430
+
431
+ if isinstance(object, Document) and object.analysis:
432
+ yield from Concept._document_iter(object.analysis, filter)
433
+ elif isinstance(object, Analysis):
434
+ yield from Concept._document_iter(object, filter)
435
+ elif isinstance(object, Sentence):
436
+ yield from Concept._sentence_iter(object, filter)
437
+ elif isinstance(object, Concept):
438
+ yield from Concept._concept_iter(object, filter, align)
439
+ else:
440
+ raise TypeError(f"Expected Document, Analysis, Sentence, or Concept but got '{type(object)}'")
441
+
442
+ @staticmethod
443
+ def next(sentence: List[Annotation], object) -> Concept:
444
+ """returns the next Concept"""
445
+ index = object.index + 1
446
+ sentence_length = len(sentence)
447
+ while index < sentence_length:
448
+ if sentence[index].is_concept:
449
+ return cast(Concept, sentence[index])
450
+ else:
451
+ index += 1
452
+ raise ErrorAnnotationNotFound
453
+
454
+ @staticmethod
455
+ def prev(sentence: List[Annotation], object) -> Concept:
456
+ """returns the prev Concept"""
457
+ index = object.index - 1
458
+ while index >= 0:
459
+ if sentence[index].is_concept:
460
+ return cast(Concept, sentence[index])
461
+ else:
462
+ index -= 1
463
+ raise ErrorAnnotationNotFound
464
+
465
+ def set_sentence_annotations_index(self, sentence_annotations: list[Annotation], annotation_idx: int):
466
+ self._sentence_annotations = sentence_annotations
467
+ self._annotation_idx = annotation_idx
468
+
469
+ def get_attribute(self, key: str):
470
+ return self._attributes[key][0]
471
+
472
+ def get_attributes(self, key: str):
473
+ return self._attributes[key]
@@ -0,0 +1,166 @@
1
+ from __future__ import annotations
2
+ from wowool.annotation.annotation import Annotation
3
+ from wowool.annotation.sentence import Sentence
4
+ from wowool.annotation.token import Token
5
+ from typing import Callable, List, cast, Iterator, Self
6
+ from wowool.analysis import Analysis
7
+
8
+
9
+ class Paragraph(Annotation):
10
+ """
11
+ :class:`Paragraph` is a class that contains all the information of a
12
+ """
13
+
14
+ FilterType = Callable[[Self], bool]
15
+
16
+ def __init__(self, begin_offset: int, end_offset: int):
17
+ """
18
+ Initialize a :class:`Paragraph` instance
19
+
20
+ :param begin_offset: Begin offset of the paragraph
21
+ :type begin_offset: ``int``
22
+ :param end_offset: End offset of the paragraph
23
+ :type end_offset: ``int``
24
+ :return: An initialized paragraph
25
+ :rtype: :class:`paragraph`
26
+ """
27
+ self._attributes = {}
28
+ super(Paragraph, self).__init__(begin_offset, end_offset)
29
+ self._sentence_annotations = None
30
+ self._dict = None
31
+ self._canonical = None
32
+ self._text = None
33
+
34
+ def _get_text(self):
35
+ """
36
+ :return: A string representation of the concept
37
+ :rtype: ``str``
38
+ """
39
+ retval = ""
40
+ prev_tk = None
41
+ for tk in [a for a in self.annotations if a.is_token]:
42
+ if prev_tk and prev_tk.end_offset != tk.begin_offset:
43
+ retval += " "
44
+ retval += tk.literal
45
+ prev_tk = tk
46
+ return retval.strip()
47
+
48
+ @property
49
+ def sentences(self) -> None | List[Sentence]:
50
+ """
51
+ :return: a list of the sentence annotations in the paragraph
52
+ :rtype: ``list[Sentence]``
53
+ """
54
+ return self._sentence_annotations
55
+
56
+ @property
57
+ def text(self):
58
+ """
59
+ :return: A string representation of the concept
60
+ :rtype: ``str``
61
+ """
62
+ if self._text is None:
63
+ self._text = self._get_text()
64
+ return self._text
65
+
66
+ def __setstate__(self, d):
67
+ self.__dict__.update(d)
68
+
69
+ def __getstate__(self):
70
+ return self.__dict__
71
+
72
+ def keys(self):
73
+ """
74
+ This function is used to convert a concept object to a dictionary
75
+
76
+ .. code-block:: python
77
+
78
+ { **concept }
79
+
80
+
81
+ :return: a list of the keys of the concept.
82
+ :rtype: list(str)
83
+
84
+
85
+ """
86
+ if not self._dict:
87
+ self._dict = self.to_json()
88
+ return self._dict.keys()
89
+
90
+ def __repr__(self) -> str:
91
+ retval = "P:" + Annotation.__repr__(self)
92
+ return retval
93
+
94
+ @staticmethod
95
+ def same_paragraph(original_text: str, prev: Sentence, next: Sentence) -> bool:
96
+ annotation = prev.annotations[-1]
97
+
98
+ if prev.is_header:
99
+ return True
100
+
101
+ prev_last_token = cast(Token, annotation) if annotation.is_token else None
102
+ if prev_last_token and prev_last_token.has_pos("Punct-Line"):
103
+ return True
104
+ if (next.begin_offset - prev.end_offset) >= 2:
105
+ doc_text = original_text[prev.end_offset : next.begin_offset]
106
+ if "\r" in doc_text:
107
+ doc_text = doc_text.replace("\r", "")
108
+ pos = doc_text.find("\n")
109
+ if pos == -1:
110
+ return True
111
+ elif (pos := doc_text.find("\n", pos + 1)) == -1:
112
+ return True
113
+ else:
114
+ return False
115
+
116
+ return True
117
+
118
+ @staticmethod
119
+ def _document_iter(doc: Analysis, original_text: str) -> Iterator[Paragraph]:
120
+
121
+ paragraph = Paragraph(0, 0)
122
+ for sentence in doc:
123
+ if paragraph._sentence_annotations is None:
124
+ paragraph._sentence_annotations = [sentence]
125
+ paragraph._begin_offset = sentence.begin_offset
126
+ else:
127
+ if Paragraph.same_paragraph(original_text, paragraph._sentence_annotations[-1], sentence):
128
+ paragraph._sentence_annotations.append(sentence)
129
+ else:
130
+ paragraph._end_offset = paragraph._sentence_annotations[-1].end_offset
131
+ yield paragraph
132
+ paragraph = Paragraph(sentence.begin_offset, 0)
133
+ paragraph._sentence_annotations = [sentence]
134
+ if paragraph._sentence_annotations:
135
+ paragraph._end_offset = paragraph._sentence_annotations[-1].end_offset
136
+ yield paragraph
137
+
138
+ @staticmethod
139
+ def iter(object, original_text=None, align: bool = True) -> Iterator[Paragraph]:
140
+ """
141
+ Iterate over the concepts in a document, an analysis, a sentence or a concept. For example:
142
+
143
+ .. code-block:: python
144
+
145
+ document = analyzer("Hello from Antwerp, said John Smith.")
146
+ for paragraph in Paragraph.iter(document):
147
+ print(paragraph)
148
+
149
+ :param object: Object to iterate
150
+ :type object: :class:`Analysis <wowool.analysis.Analysis>`
151
+
152
+ :return: A generator expression yielding paragraphs
153
+ :rtype: :class:`Concept <wowool.annotation.paragraph.Paragraph>`
154
+ """
155
+ from wowool.document.document import Document
156
+ from wowool.analysis import Analysis
157
+
158
+ if original_text is None:
159
+ original_text = object.text
160
+
161
+ if isinstance(object, Document) and object.analysis:
162
+ yield from Paragraph._document_iter(object.analysis, original_text)
163
+ elif isinstance(object, Analysis):
164
+ yield from Paragraph._document_iter(object, original_text)
165
+ else:
166
+ raise TypeError(f"Expected Document, Analysis, but got '{type(object)}'")