Skip to content

Commit 0c7975c

Browse files
committed
Adopted new hyperbase API (0.9.0) with ParseResult
1 parent 4a9e0bf commit 0c7975c

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Changelog
22

3-
## [0.1.1] - work in progress
3+
## [0.2.0] - work in progress
44

55
### Added
66

77
### Changed
88

9+
- Adopted new hyperbase API (0.9.0) with ParseResult.
10+
911
### Removed
1012

1113
## [0.1.0] - 02-04-2026 - extracted from graphbrain

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.1
1+
0.2.0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ classifiers = [
2626
"Topic :: Scientific/Engineering :: Information Analysis",
2727
]
2828
dependencies = [
29-
"hyperbase>=0.8.0",
29+
"hyperbase>=0.9.0",
3030
"scikit-learn>=1.3.0",
3131
"spacy>=3.8.0",
3232
"torch>=2.0.0",

src/hyperbase_parser_ab/parser.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import hyperbase.constants as const
1010
from hyperbase.hyperedge import Atom, Hyperedge, build_atom, hedge, non_unique, unique, UniqueAtom
11-
from hyperbase.parsers import Parser
11+
from hyperbase.parsers import ParseResult, Parser
1212

1313
from hyperbase_parser_ab.alpha import Alpha
1414
from hyperbase_parser_ab.lang_models import get_spacy_models
@@ -205,19 +205,19 @@ def debug_msg(self, msg: str) -> None:
205205
if self.debug:
206206
print(msg)
207207

208-
def parse_sentence(self, sentence: str) -> list[dict[str, object]]:
208+
def parse_sentence(self, sentence: str) -> list[ParseResult]:
209209
# This runs spacy own sentensizer anyway...
210210

211211
sentence = re.sub(r'\s+', ' ', sentence).strip()
212212

213213
if self.nlp:
214214
self.reset(sentence)
215-
parses: list[dict[str, object]] = []
215+
parses: list[ParseResult] = []
216216
try:
217217
self.doc = self.nlp(sentence)
218218
offset: int = 0
219219
for sent in self.doc.sents:
220-
parse: dict[str, object] | None = self.parse_spacy_sentence(sent, offset=offset)
220+
parse: ParseResult | None = self.parse_spacy_sentence(sent, offset=offset)
221221
if parse:
222222
parses.append(parse)
223223
offset += len(sent)
@@ -228,7 +228,7 @@ def parse_sentence(self, sentence: str) -> list[dict[str, object]]:
228228
raise RuntimeError("spaCy model failed to initialize.")
229229

230230
def parse_spacy_sentence(self, sent: Span, atom_sequence: list[Atom] | None = None,
231-
offset: int = 0) -> dict[str, object] | None:
231+
offset: int = 0) -> ParseResult | None:
232232
try:
233233
if atom_sequence is None:
234234
atom_sequence = self._build_atom_sequence(sent)
@@ -257,13 +257,14 @@ def parse_spacy_sentence(self, sent: Span, atom_sequence: list[Atom] | None = No
257257
if edge is None:
258258
return None
259259

260-
return {
261-
'edge': edge,
262-
'failed': failed,
263-
'text': str(sent).strip(),
264-
'tokens': [str(token) for token in sent],
265-
'tok_pos': _generate_tok_pos(atom2word, edge)
266-
}
260+
tok_pos_str = _generate_tok_pos(atom2word, edge)
261+
return ParseResult(
262+
edge=edge,
263+
text=str(sent).strip(),
264+
tokens=[str(token) for token in sent],
265+
tok_pos=hedge(tok_pos_str),
266+
failed=failed,
267+
)
267268
except Exception as e:
268269
print('Caught exception: {} while parsing: "{}"'.format(str(e), str(sent)))
269270
traceback.print_exc()

0 commit comments

Comments
 (0)