Skip to content

Nested matchers #30

Description

@mikhail-barg

Hi, we've been using IronMeta in production for a while now, and are pretty happy with it (even more after #24). Thanks for the project!

Currently we are looking towards using it for named entity recognition (NER) task together with general pattern matching.

Consider for example phrase I want ten apples. We'd like to have a matcher that would answer if the phrase matches I want <N> apples pattern, AND would return value of N as int.

It's clear that we could write a specific grammar for this task, but consider a more complex example: I want <N> <Fruit> or I want <N> <Fruit> delivered at <Address> on <DayOrDate>.

It's still possible to write a specific grammar for every example, but it would cause huge duplication of code for specific entity matchers.

For example we already have a matcher that could transform words into integers ("ten thousands" -> 10000), so it would be great to have a way of re-using it without copy-pasting it as a part of specific grammar.

I imagine it to be something like this:

ironmeta IntMatcher<string, int>: Matcher<string, int>
{
...
}

enum Fruits
{
 Orange,
 Apple
}

ironmeta FruitsMatcher<string, Fruits>: Matcher<string, Fruits>
{
...
}

class Result
{
   int number;
   Fruits fruit;
}

ironmeta MainMatcher<string, Result>: Matcher<string, Result>
{
  Expression = "I" "want" IntMatcher:n FruitsMatcher:fr -> { return new Result() { number = n; fruit = fr }; };
}

What do you think? Is it possible to implement something like this? Or maybe there are simpler ways?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions