fcbond / ltdb

Linguistic Type Data-Base
Other
2 stars 2 forks source link

PyDelphin v1.0.0 upgrade plan #4

Open goodmami opened 5 years ago

goodmami commented 5 years ago

This repository came up when I was searching GitHub for functionality of PyDelphin that may be changing. The following will break with the v1.0.0 version of PyDelphin, so you can either pin your code to the latest v0.9.x version or port to the new API. This issue is just meant to document the changes that may be necessary when you decide to port; no action is needed just yet.

Old:

[...]
import delphin.mrs
[...]
import delphin.mrs.xmrs
import delphin.mrs.simplemrs
[...]
        profile = itsdb.ItsdbProfile(root)
        [...]
        for  row in profile.read_table('item'):
            items[row['i-id']] = (row['i-input'], row['i-comment'])
        for row in profile.read_table('result'):
            [...]
            try:
                mrs_obj = delphin.mrs.simplemrs.loads(mrs_string, single=True, version=1.1, errors='strict')
                # mrs_obj = delphin.mrs.simplemrs.loads(row['mrs'], single=True, version=1.1, strict=False, errors='warn')
                # mrs_string = row['mrs']  # CHANGING
                mrs_json = delphin.mrs.xmrs.Mrs.to_dict(mrs_obj)
                dmrs_json = delphin.mrs.xmrs.Dmrs.to_dict(mrs_obj)

New:

[...]
from delphin.mrs import simplemrs
from delphin.mrs import mrsjson
from delphin.dmrs import dmrsjson
[...]
        profile = itsdb.TestSuite(root)
        [...]
        for  row in profile['item']:
            items[row['i-id']] = (row['i-input'], row['i-comment'])
        for row in profile['result']:
            [...]
            try:
                mrs_obj = simplemrs.decode(mrs_string)
                mrs_json = mrsjson.to_dict(mrs_obj)
                dmrs_json = dmrsjson.to_dict(mrs_obj)

This is a pretty basic and direct porting to the new API. You may also consider restructuring the loops to use TSQL queries, or at least itsdb.join(), partly and importantly because parse-id cannot be relied on to be the same as i-id.

Also, you use errors='strict' but I was thinking of removing that functionality. Is it useful for you?

fcbond commented 5 years ago

Thanks for the heads up.

I would prefer to port, if you let me know when I should. I would be happy to move to TSQL queries, but it is not a high priority.

I don't need errors='strict'.

On Tue, Nov 27, 2018 at 2:08 PM Michael Wayne Goodman < notifications@github.com> wrote:

This repository came up when I was searching GitHub for functionality of PyDelphin that may be changing. The following will break with the v1.0.0 version of PyDelphin, so you can either pin your code to the latest v0.9.x version or port to the new API. This issue is just meant to document the changes that may be necessary when you decide to port; no action is needed just yet.

Old:

[...]import delphin.mrs [...]import delphin.mrs.xmrsimport delphin.mrs.simplemrs [...] profile = itsdb.ItsdbProfile(root) [...] for row in profile.read_table('item'): items[row['i-id']] = (row['i-input'], row['i-comment']) for row in profile.read_table('result'): [...] try: mrs_obj = delphin.mrs.simplemrs.loads(mrs_string, single=True, version=1.1, errors='strict')

mrs_obj = delphin.mrs.simplemrs.loads(row['mrs'], single=True, version=1.1, strict=False, errors='warn')

            # mrs_string = row['mrs']  # CHANGING
            mrs_json = delphin.mrs.xmrs.Mrs.to_dict(mrs_obj)
            dmrs_json = delphin.mrs.xmrs.Dmrs.to_dict(mrs_obj)

New:

[...]from delphin.mrs import simplemrsfrom delphin.mrs import mrsjsonfrom delphin.dmrs import dmrsjson [...] profile = itsdb.TestSuite(root) [...] for row in profile['item']: items[row['i-id']] = (row['i-input'], row['i-comment']) for row in profile['result']: [...] try: mrs_obj = simplemrs.decode(mrs_string) mrs_json = mrsjson.to_dict(mrs_obj) dmrs_json = dmrsjson.to_dict(mrs_obj)

This is a pretty basic and direct porting to the new API. You may also consider restructuring the loops to use TSQL queries, or at least itsdb.join(), partly and importantly because parse-id cannot be relied on to be the same as i-id.

Also, you use errors='strict' but I was thinking of removing that functionality. Is it useful for you?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fcbond/ltdb/issues/4, or mute the thread https://github.com/notifications/unsubscribe-auth/ABD8xnBQjQ3oG9o6fu6M_Cj9OJUdytHSks5uzNbigaJpZM4Y0zFt .

-- Francis Bond http://www3.ntu.edu.sg/home/fcbond/ Division of Linguistics and Multilingual Studies Nanyang Technological University