kylebgorman / pynini

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

function "project" expects an argument with Pynini 2.1.3 #38

Closed wrznr closed 3 years ago

wrznr commented 3 years ago

I recently moved to version 2.1.3. Now, project expects an argument. Did you change the API?

Traceback (most recent call last):
  File "/home/kmw/Documents/Work/timur/env/bin/timur", line 11, in <module>
    load_entry_point('timur', 'console_scripts', 'timur')()
  File "/home/kmw/Documents/Work/timur/env/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/kmw/Documents/Work/timur/env/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/kmw/Documents/Work/timur/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/kmw/Documents/Work/timur/env/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/kmw/Documents/Work/timur/env/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/kmw/Documents/Work/timur/timur/scripts/timur.py", line 76, in build
    timur = fsts.TimurFst()
  File "/home/kmw/Documents/Work/timur/timur/fsts/timur_fst.py", line 25, in __init__
    self.__syms = symbols.Symbols(pynini.SymbolTable.read_text(resource_filename(Requirement.parse("timur"), 'timur/data/syms.txt')))
  File "/home/kmw/Documents/Work/timur/timur/symbols/symbols.py", line 46, in __init__
    self.__characters = pynini.string_map(chars, input_token_type=alphabet, output_token_type=alphabet).project().optimize()
TypeError: project() takes exactly one argument (0 given)

(Code is here: https://github.com/wrznr/timur/blob/2fed6c980eda34a318aff088cac96f4d7ba19d05/timur/symbols/symbols.py#L46)

Documentation at http://www.openfst.org/twiki/bin/view/GRM/PyniniDocs says nothing about arguments...

kylebgorman commented 3 years ago

Hi there, yes. Rather than treating one direction of projection as "default" and deriving the other with a non-default argument we follow the pattern used in other OpenGrm tools: one must specify "input" or "output" as an argument. Information about the API is discoverable using the in-module help docs:

>>> help(pynini.project)

the type stubs (static type checking tools like mypy will tell you that it expects a mandatory "input" or "output" argument), or by reading the NEWS file updated with every release.

So you know API changes came fast in 2020 (the library gained many new internal users and we were in the process of developing a book that uses the library heavily) but far fewer are anticipated going forward.