kylebgorman / pynini

Read-only mirror of Pynini
http://pynini.opengrm.org
Apache License 2.0
120 stars 26 forks source link

SymbolTableIterator class #23

Closed lxkain closed 4 years ago

lxkain commented 4 years ago

Does this class still exist? I used to be able to

for i, s in ni.SymbolTableIterator(word_table):
    print(i, s)

but I don't see a replacement/workaround for this. I do see that some changes were made ("Internal improvements to the symbol table iterator interface").

kylebgorman commented 4 years ago

Just place the symbol table itself in an "iteration context" (i.e., in the context "for i, s in ___:") and you'll get the iteration interpretation. It was never our intention for someone to iterate over a symbol table the way you are. There may still be a pseudo-private class that does what you want the way you were earlier, but I'd have to go dig for it...

Example, for fun:

sym = pynini.SymbolTable() sym.add_symbol("") sym.add_symbol("foo") sym.add_symbol("bar") for (index, symbol) in sym: print(index, symbol)

Similarly the best way to access the state iterator is to use the .states() method, and for the arc iterators, the .arcs() and .mutable_arcs() methods---I think that should cover the major iterators.

We're in the process of moving from what you might call "Google"-style iterators, developed during the C++03 era, which have a signature like:

void Next(); bool Done() const; const T &Value() const; void Reset(); // Optional.

to more C++17 (onward)-style iterators that are compatible with the newish "range-for" construction. The SymbolTableIterator was the first to go under the knife and it triggered a bunch of restructuring in the Python wrapper. Truly, this was a major release.

On Fri, Feb 28, 2020 at 1:04 PM Alexander Kain notifications@github.com wrote:

Does this class still exist? I used to be able to

for i, s in ni.SymbolTableIterator(word_table): print(i, s)

but I don't see a replacement/workaround for this. I do see that some changes were made ("Internal improvements to the symbol table iterator interface").

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kylebgorman/pynini/issues/23?email_source=notifications&email_token=AABG4OOSOCWVQY5GUDF4XPLRFFG37A5CNFSM4K5WRAR2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IRGAT4Q, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABG4OKNKJSR4W2R4YBQUI3RFFG37ANCNFSM4K5WRARQ .

lxkain commented 4 years ago

Thank you, I probably tried the more pythonic way years ago and perhaps it didn't work then, I'm not sure what happened.