Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make reverse recursive #33

Open
arubehn opened this issue Aug 7, 2024 · 7 comments
Open

Make reverse recursive #33

arubehn opened this issue Aug 7, 2024 · 7 comments

Comments

@arubehn
Copy link

arubehn commented Aug 7, 2024

I'd suggest making the reverse function recursive; since I think that is the most common use case. For an exemplary Word a b + c d, reverse() would make it c d + a b, swapping the order of the morphemes, but not the segments inside the morphemes. I think, in the regular use case, you would rather want to end up with d c + b a.

If you agree and think this is useful, I would quickly implement that; as it should be fairly simply.

@LinguList
Copy link
Contributor

@xrotwang, would you agree with this? I would agree, since reverse has a direct use in morpheme segmentation (whwere we use the new classes).

@xrotwang
Copy link
Contributor

xrotwang commented Aug 7, 2024

I wouldn't say that either type of reversing is more intuitive, but the clear use case of "going through the list backwards" seems to favor @arubehn 's idea.

@LinguList
Copy link
Contributor

I think if we say that slicing only goes for the elements that are addressed, we can have a reverse() function that does a full reverse. But the case of

w = Word.from_segments("a b c + d e f")
w[::-1]

should probably yield:

["d", "e", "f"], ["a", "b", "c"]

@xrotwang
Copy link
Contributor

xrotwang commented Aug 7, 2024

Oh, wait. What reverse function are we talking about? Python's builtin reversed? Or list.reverse? Anyway, thinking about these makes me not want a reverse that does something different. If we need the functionality, we should call it something different.

@arubehn
Copy link
Author

arubehn commented Aug 7, 2024

I was thinking about list.reverse -- but I think you are right, we might not want to change the behavior of a native function by overwriting it. I still think it would be nice to have this functionality around - so maybe we should just call it something else then, e.g. reverse_segments?

@LinguList
Copy link
Contributor

What about an independent function that just reverts a TypedSequence? It is really for the Word(Morpheme) case, so we can have some short cut:

def revert(word: linse.Word):
    return [morpheme[::-1] for morpheme in word[::-1]

@xrotwang
Copy link
Contributor

xrotwang commented Aug 7, 2024

reversed_segments would feel transparent to me - and somewhat in sync with the builtin function being named reversed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants