Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Problem passing string value as docid #26

Closed
oktaal opened this issue Nov 17, 2023 · 2 comments
Closed

Problem passing string value as docid #26

oktaal opened this issue Nov 17, 2023 · 2 comments
Assignees
Labels

Comments

@oktaal
Copy link

oktaal commented Nov 17, 2023

When creating a Frog instance such as:

from frog import Frog, FrogOptions
frog_instance = Frog(FrogOptions(
    xmlout=True,
    docid='DOCID',
    mwu=False,
    parser=False
))

I get the following error:

  File "frog_wrapper.pyx", line 80, in frog.FrogOptions.__init__
  File "frog_wrapper.pyx", line 125, in frog.FrogOptions.__setitem__
  File "<stringsource>", line 15, in string.from_py.__pyx_convert_string_from_py_std__in_string
TypeError: expected bytes, str found

When I add an encode() to docid='DOCID' it works:

from frog import Frog, FrogOptions
frog_instance = Frog(FrogOptions(
    xmlout=True,
    docid='DOCID'.encode(),
    mwu=False,
    parser=False
))

Reading:

elif key.lower() in ('docid','id'):
self.capi.insert(<string>b"id", <string>value)
elif key.lower() in ('numthreads','threads'):
self.capi.insert(<string>b"threads",<string>value)
else:
if key == 'x':
self.shadow['xmlin'] = True
elif key == 'X':
self.shadow['xmlout'] = True
self.capi.insert(<string>key, <string>value)
def finish(self):
v = "".join(self.skip)
self.capi.insert(<string>b"skip", <string>v.encode('utf-8'))

I think it might need this for id and threads as well, such as it already does for skip, and/or it might need to check if the value has already been encoded to bytes.

@proycon
Copy link
Owner

proycon commented Nov 20, 2023

Thanks, good point indeed! I'll adapt it so it's more intuitive and you can pass strings.

proycon added a commit that referenced this issue Nov 20, 2023
For backward-compatibility, passing bytes is still allowed as well
@proycon proycon self-assigned this Nov 20, 2023
@proycon proycon added the bug label Nov 20, 2023
@proycon
Copy link
Owner

proycon commented Nov 24, 2023

Fixed in v0.6.9 release

@proycon proycon closed this as completed Nov 24, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants