Skip to content

Strip target text of leading and trailing whitespace #40

Description

@vestedinterests

Great package, and I think it offers a very easy-to-use implementation for targeted sentiment classification! I had a brief question: it took me a while to track down that I think the package fails for me always whenever the target has a leading or trailing white space? I know that it is recommended that the whitespace should be in the left- and right-contexts, but maybe a simple .strip() could prevent a

from NewsSentiment import TargetSentimentClassifier
tsc = TargetSentimentClassifier()

This will work fine:

tsc.infer(
    "The context ",
    "around a target",
    "matters."
)

but either of the following will produce an error message:

tsc.infer(
    "The context ",
    "around a target ",
    "matters."
)
tsc.infer(
    "The context ",
    " around a target",
    "matters."
)

It fails then with

UnboundLocalError: local variable 'text' referenced before assignment

which took me a while to debug.

I would suggest that it's either a simple check which raises an Error, but informs the user that a whitespace should not in the target word, or if you think it's not an issue, to perform the whitespace stripping yourself. I could suggest a simple commit, but I didn't know where to best place it, or what your opinion would be on the two possible approaches.

(tested on Python 3.10, NewsSentiment 1.2.28)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions