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

Support single word rule composition #110

Open
patapizza opened this issue Nov 15, 2017 · 5 comments
Open

Support single word rule composition #110

patapizza opened this issue Nov 15, 2017 · 5 comments

Comments

@patapizza
Copy link
Contributor

patapizza commented Nov 15, 2017

Today Duckling doesn't allow to create multiple patterns to match against a single word.
As a result, we can't compose rules/dimensions and have to duplicate the regexes.

This is the case for DE (e.g. here and here), NL (e.g. here), EL (e.g. here), and RU (e.g. here).

@chessai
Copy link
Contributor

chessai commented Jan 12, 2021

Yes, this is a somewhat annoying thing about hacking on duckling.

@emlautarom1
Copy link
Contributor

I've been thinking about how we could approach this issue. My idea is to add a rule to each language that splits single words so we can reuse the rules that already exist.


Assume that we have Language X and it has rules for hello, world and intersection, so it correctly parses hello (with hello rule), world (with world rule), and hello world, world hello, hello hello, world world (with intersection rule).

What I would like to do is add a single-word decomposition rule that will handle helloworld, hellohello, worldhello and worldworld. The idea is that this rule will only split the word into subwords which then will be picked up by the intersection rule.

For example, rule single-word decomposition converts helloworld into hello world. Then, rule intersection picks hello world and works as expected.

The single-word decompositon rule would need to know in advance all possible subwords so then it can separate them. A rough implementation would be something like:

ruleSingleWordDecomposition :: Rule
ruleSingleWordDecomposition = Rule
  { name = "single-word decomposition"
  , pattern =
    [ regex "(\\S+)" -- we match 'single' words
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (w:_)):_) -> do
        let rgx = "(hello|world)" :: String -- we need to compute in advance a big regex of possible "subwords"
        let ws = Text.pack <$> getAllTextMatches (show w =~ rgx)
        Just $ Token RegexMatch $ GroupMatch ws -- How do we return the "subwords" so other rules can pick them up?
      _ -> Nothing
  }

Note: we need to split the "single word" in Haskell (let ws = Text.pack <$> getAllTextMatches (show w =~ rgx)) since we can't do it with pure regexes AFAIK

In this case, our single-word decomposition rule knows that "single words" can be composed only from the "subwords" hello and world.

The main issue that I found with this is how to use the output of this rule as input for the remaining rules (they don't pick it up). So, even if we're able to build the required regex and split the "single word" into "subwords" I can't seem to redirect them to other rules.

I'm trying to avoid adding special cases or hacking into the internals of Duckling (Engine.hs and the like), so any hint would be appreciated.

@emlautarom1
Copy link
Contributor

emlautarom1 commented Oct 15, 2021

One quick note, the mentioned examples in the first comment aren't permalinks so I can't be sure to what they refer to. I understand that this issue is related to:

@emlautarom1
Copy link
Contributor

@chessai Do you think that this could work?

@andhai
Copy link
Contributor

andhai commented Jun 13, 2022

Regarding @emlautarom1's interesting suggestion, I see two problems that should be considered before going this route.

First, decomposing German number words like "dreiundzwanzig" 'three.and.twenty' (23) can lead to unnwanted ambiguities because "drei und zwanzig" 'three and twenty' is also a grammatical phrase in German. Consider, for instance, the sentence "sie wählten zwischen dreiundzwanzig Kandidaten" 'they made a selection between twenty three candidates'. The problem is that the sentence "sie wählten zwischen drei und zwanzig Kandidaten" 'they made a selection between three candidates and twenty candidates'. Hence, the suggested decomposition makes the two sentences indistinguishable.

Similarly, if single-word decomposition is applied the compound "zweihundertjährige" 'two.hundred.year.old.PL' and the phrase "zwei hundertjährige" 'two hundred.year.old.PL' are converted to the same string. Thus, the difference between sentences like "sie fällten zweihundertjährige Eichen" 'they chopped oak trees that were two hundred years old' and "sie fällten zwei hundertjährige Eichen" 'they chopped two oak trees that were one hundred years old' is erased.

So the upshot is that we lose information by applying single-word decomposition.

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

No branches or pull requests

5 participants
@patapizza @chessai @andhai @emlautarom1 and others