-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dsn.s_expr.concoct_history for testing purposes
- Loading branch information
1 parent
1a49718
commit 0cdfc73
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
>>> from hashstore import NoutHashStore | ||
>>> from memoization import Stores, Memoization | ||
>>> from dsn.historiography.legato import HistoriographyNoteNoutHash, HistoriographyNoteNout, HistoriographyNoteCapo | ||
>>> from dsn.s_expr.legato import NoteNout, NoteCapo, NoteNoutHash | ||
|
||
>>> from dsn.s_expr.from_python import s_expr_from_python | ||
>>> from dsn.s_expr.construct_x import construct_x | ||
>>> from dsn.s_expr.concoct import concoct_history | ||
|
||
>>> p = NoutHashStore(NoteNoutHash, NoteNout, NoteCapo) | ||
>>> historiography_note_nout_store = NoutHashStore(HistoriographyNoteNoutHash, HistoriographyNoteNout, HistoriographyNoteCapo) | ||
>>> stores = Stores(p, historiography_note_nout_store) | ||
>>> m = Memoization() | ||
|
||
>>> s_expr = s_expr_from_python(("foo", ("bar",))) | ||
>>> result = concoct_history(m, stores, s_expr) | ||
>>> construct_x(m, stores, result[-1].nout_hash) | ||
(foo (bar)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from dsn.s_expr.clef import BecomeNode, TextBecome, Insert | ||
from dsn.s_expr.structure import TreeNode, TreeText | ||
from dsn.s_expr.utils import stored_nouts_for_notes_da_capo | ||
|
||
|
||
def concoct_history(m_, stores, s_expr): | ||
"""Given an s_expression, concoct a history that produces the s_expression. | ||
The method of concocting is The Simplest Thing That Could Possibly Work, i.e. in the concocted history things are | ||
created in the order of (spatial) appearance; each child is added only once using a single Insert (which contains | ||
the child's entire history). | ||
The history is returned as a list of NoutAndHash (which have been added to the store, a.k.a. "seen") | ||
""" | ||
|
||
if isinstance(s_expr, TreeNode): | ||
notes = [BecomeNode()] | ||
|
||
for i, child in enumerate(s_expr.children): | ||
child_history = concoct_history(m_, stores, child) | ||
notes.append(Insert(i, child_history[-1].nout_hash)) | ||
|
||
if isinstance(s_expr, TreeText): | ||
notes = [TextBecome(s_expr.unicode_)] | ||
|
||
return list(stored_nouts_for_notes_da_capo(stores.note_nout, notes)) # wrapped in list to ensure it happens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters