API Reference¶
Main functions¶
hyperbase
¶
hedge(source)
¶
Create a hyperedge.
Source code in src/hyperbase/builders.py
load_edges(source, lazy=False)
¶
Load a sequence of hyperedges from various sources.
source can be:
- A path to a .jsonl file (one JSON object per line, each treated as
a ParseResult).
- A path to a .json file (must contain a JSON array, items handled as
the sequence case below).
- A path to any other text file (one edge string per line, fed to
hedge).
- Any iterable of items accepted by hedge. dict items are first
converted to ParseResult via ParseResult.from_dict.
If lazy is True, return a generator (lazy evaluation).
If lazy is False (default), return a list.
Source code in src/hyperbase/loaders.py
get_parser(name, params=None, **kwargs)
¶
Instantiate a parser plugin by name.
Looks up name in the hyperbase.parsers entry-point group and
returns an instance of the registered :class:Parser subclass.
params is a dictionary of parser parameters. For backwards compatibility, keyword arguments are merged into params (explicit params entries take precedence).
Raises :class:ValueError if the parser is not installed.
Source code in src/hyperbase/parsers/__init__.py
Hyperedge module¶
hyperbase.hyperedge
¶
Hyperedge
dataclass
¶
Non-atomic hyperedge.
Source code in src/hyperbase/hyperedge.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
atom
property
¶
True if edge is an atom.
not_atom
property
¶
True if edge is not an atom.
t
property
¶
Edge type. (this property is a shortcut for Hyperedge.type())
mt
property
¶
Edge main type. (this property is a shortcut for Hyperedge.mtype())
ct
property
¶
Edge connector type. (this property is a shortcut for Hyperedge.connector_type())
cmt
property
¶
Edge connector main type. (this property is a shortcut for Hyperedge.mconnector_type())
match(pattern)
¶
Match this edge against a pattern. See match_pattern for details.
Source code in src/hyperbase/hyperedge.py
label()
¶
Generate human-readable label for edge.
Source code in src/hyperbase/hyperedge.py
inner_atom()
¶
The inner atom inside of a modifier structure.
For example, condider: (red/M shoes/C) The inner atom is: shoes/C Or, the more complex case: ((and/J slow/M steady/M) go/P) Yields: gp/P
This method should not be used on structures that contain more than one inner atom, for example concepts constructed with builders or relations.
The inner atom of an atom is itself.
Source code in src/hyperbase/hyperedge.py
connector_atom()
¶
The inner atom of the connector.
For example, condider: (does/M (not/M like/P.so) john/C chess/C) The connector atom is: like/P.so
The connector atom of an atom is None.
Source code in src/hyperbase/hyperedge.py
atoms()
¶
Returns the set of atoms contained in the edge.
For example, consider the edge: (the/md (of/br mayor/cc (the/md city/cs))) in this case, edge.atoms() returns: [the/md, of/br, mayor/cc, city/cs]
Source code in src/hyperbase/hyperedge.py
all_atoms()
¶
Returns a list of all the atoms contained in the edge. Unlike atoms(), which does not return repeated atoms, all_atoms() does return repeated atoms if they are different objects.
For example, consider the edge: (the/md (of/br mayor/cc (the/md city/cs))) in this case, edge.all_atoms() returns: [the/md, of/br, mayor/cc, the/md, city/cs]
Source code in src/hyperbase/hyperedge.py
size()
¶
The size of an edge is its total number of atoms, at all depths.
depth()
¶
Returns maximal depth of edge, an atom has depth 0.
Source code in src/hyperbase/hyperedge.py
contains(needle)
¶
Checks recursively if 'needle' is contained in edge.
subedges()
¶
Returns all the subedges contained in the edge, including atoms and itself.
replace_atom(old, new, unique=False)
¶
Returns edge built by replacing every instance of 'old' in this edge with 'new'.
Keyword argument: unique -- match only the exact same instance of the atom, i.e. UniqueAtom(self) == UniqueAtom(old) (default: False)
Source code in src/hyperbase/hyperedge.py
simplify(subtypes=False, namespaces=False)
¶
Returns a version of the edge with simplified atoms.
Keyword arguments: subtypes -- include subtypes (default: True). namespaces -- include namespaces (default: True).
Source code in src/hyperbase/hyperedge.py
type()
¶
Returns the type of this edge as a string. Type inference is performed.
Source code in src/hyperbase/hyperedge.py
connector_type()
¶
Returns the type of the edge's connector. If the edge has no connector (i.e. it's an atom), then None is returned.
Source code in src/hyperbase/hyperedge.py
mtype()
¶
Returns the main type of this edge as a string of one character. Type inference is performed.
connector_mtype()
¶
Returns the main type of the edge's connector. If the edge has no connector (i.e. it's an atom), then None is returned.
Source code in src/hyperbase/hyperedge.py
atom_with_type(atom_type)
¶
Returns the first atom found in the edge that has the given 'atom_type', or whose type starts with 'atom_type'. If no such atom is found, returns None.
For example, given the edge (+/B a/Cn b/Cp) and the 'atom_type' c, this function returns: a/Cn If the 'atom_type' is 'Cp', the it will return: b/Cp
Source code in src/hyperbase/hyperedge.py
argroles()
¶
Returns the argument roles string of the edge, if it exists. Otherwise returns empty string.
Argument roles can be return for the entire edge that they apply to, which can be a relation (R) or a concept (C). For example:
((not/M is/P.sc) bob/C sad/C) has argument roles "sc", (of/B.ma city/C berlin/C) has argument roles "ma".
Argument roles can also be returned for the connectors that define the outer edge, which can be of type predicate (P) or builder (B). For example:
(not/M is/P.sc) has argument roles "sc", of/B.ma has argument roles "ma".
Source code in src/hyperbase/hyperedge.py
replace_argroles(argroles)
¶
Returns an edge with the argroles of the connector atom replaced with the provided string. Returns same edge if the atom does not contain a role part.
Source code in src/hyperbase/hyperedge.py
add_argument(edge, argrole, pos=None)
¶
Returns a new edge with the provided edge and its argroles inserted at the specified position. If pos is not provided, the argument is appended at the end.
Source code in src/hyperbase/hyperedge.py
arguments_with_role(argrole)
¶
Returns the list of edges with the given argument role.
Source code in src/hyperbase/hyperedge.py
Atom
dataclass
¶
Bases: Hyperedge
Atomic hyperedge.
Source code in src/hyperbase/hyperedge.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | |
atom
property
¶
True if edge is an atom.
not_atom
property
¶
True if edge is not an atom.
parts()
¶
root()
¶
replace_atom_part(part_pos, part)
¶
Build a new atom by replacing an atom part in a given atom.
Source code in src/hyperbase/hyperedge.py
label()
¶
roots()
¶
role()
¶
Returns the role of this atom as a list of the subrole strings.
The role of an atom is its second part, right after the root. A dot notation is used to separate the subroles. For example, the role of hyperbase/Cp.s/1 is:
Cp.s
For this case, this function returns:
['Cp', 's']
If the atom only has a root, it is assumed to be a conjunction. In this case, this function returns the role with just the generic conjunction type:
['J'].
Source code in src/hyperbase/hyperedge.py
type()
¶
Returns the type of the atom (first subrole, default 'J').
Parsers module¶
hyperbase.parsers
¶
Parser
¶
Source code in src/hyperbase/parsers/parser.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
accepted_params()
classmethod
¶
Return the set of parameters this parser accepts.
Each key is a parameter name. The value is a dict with:
- "type": the expected Python type (e.g. str, int).
- "default": the default value (or None if required).
- "description": a short human-readable description.
- "required": whether the parameter must be provided.
Subclasses should merge their own parameters with the result of
super().accepted_params() so that common parameters like
max_depth remain discoverable.
Source code in src/hyperbase/parsers/parser.py
cache_key_from_settings(settings)
classmethod
¶
Build a cache key tuple from a settings dict.
The default implementation produces one (name, value) pair
per entry in :meth:accepted_params, sorted by name. Two
settings dicts that yield the same key are guaranteed to
produce equivalent parser instances.
Source code in src/hyperbase/parsers/parser.py
format_cache_key(cache_key)
classmethod
¶
Render a cache key produced by :meth:cache_key_from_settings
as a human-readable string for the REPL /parsers command.
Source code in src/hyperbase/parsers/parser.py
install_repl(session)
¶
Hook for parser plugins to extend the Hyperbase REPL.
Override this to register parser-specific REPL behavior on
session (a :class:hyperbase.cli.repl.ReplSession). The
session exposes the following registration methods:
register_command(name, help, handler)-- add a slash command callable as/name.register_setting(name, default, type_, description="")-- expose an extra REPL-only setting (e.g. a display toggle) that can be changed via/set.register_pre_result_hook(hook)-- run hook after parsing but before the parse result panel is rendered.register_post_result_hook(hook)-- run hook after the parse result panel is rendered.register_stats_provider(provider)-- supply extra(label, value)rows for the statistics table.
Hooks receive a :class:~hyperbase.parsers.repl_api.ReplContext
object. The default implementation is a no-op.
Source code in src/hyperbase/parsers/parser.py
parse_batch(sentences)
¶
Parse multiple sentences. Subclasses may override with a true batched implementation (e.g. a single CT2 call).
Source code in src/hyperbase/parsers/parser.py
parse(text, batch_size=8, progress=False)
¶
Sentensize text, then parse all sentences in batches.
Returns a flat list of parse results across all sentences.
Source code in src/hyperbase/parsers/parser.py
parse_to_jsonl(text, output, batch_size=8, progress=False)
¶
Parse text and write results to a JSONL file.
Each ParseResult is serialized as one JSON line.
Source code in src/hyperbase/parsers/parser.py
parse_source(source, reader='auto', batch_size=8, progress=False)
¶
Read text blocks from source and parse each one.
Automatically selects (or explicitly uses) a reader, then yields one list of parse results per text block.
Source code in src/hyperbase/parsers/parser.py
parse_source_to_jsonl(source, output, reader='auto', batch_size=8, progress=False)
¶
Read source, parse every block, and write results to a JSONL file.
Each ParseResult is serialized as one JSON line.
Source code in src/hyperbase/parsers/parser.py
ReplContext
dataclass
¶
Context passed to REPL hooks during parse_text.
Hooks may inspect the parse output and use session to access
the console, formatter, settings, and the parser itself.
Source code in src/hyperbase/parsers/repl_api.py
session
instance-attribute
¶
The :class:ReplSession (duck-typed). Exposes parser,
console, settings, formatter, plus the register_*
methods documented below.
text
instance-attribute
¶
The raw input text the user typed.
parse_result
instance-attribute
¶
The full list returned by parser.parse(text).
edge
instance-attribute
¶
The primary parsed edge (parse_result[0].edge), or None
if parsing produced no result.
tokens
instance-attribute
¶
The tokens for the primary parse, or None if absent.
elapsed_time
instance-attribute
¶
Wall-clock parse time in seconds.
list_parsers()
¶
Return all installed parser plugins.
Each plugin registers via the hyperbase.parsers entry-point group
in its pyproject.toml::
[project.entry-points."hyperbase.parsers"]
myparser = "my_package:MyParser"
Source code in src/hyperbase/parsers/__init__.py
get_parser(name, params=None, **kwargs)
¶
Instantiate a parser plugin by name.
Looks up name in the hyperbase.parsers entry-point group and
returns an instance of the registered :class:Parser subclass.
params is a dictionary of parser parameters. For backwards compatibility, keyword arguments are merged into params (explicit params entries take precedence).
Raises :class:ValueError if the parser is not installed.