Open tbaptista opened 6 years ago
Hi @tbaptista, thanks for reaching out.
This is interesting. Can you tell a bit more about this? What are typical sentences you'd like to parse and what would be the resolution?
Hi @patapizza, thanks for the quick reply.
Here are some examples. Let's assume that we configure our fiscal calendar with a 4-4-5 pattern, starting in September, and ending the week on a Saturday (this is one example from https://en.wikipedia.org/wiki/4–4–5_calendar).
"last quarter of 2015"
should parse to ...{"value":"2015-05-31T00:00:00.000-07:00","grain":"quarter","type":"value"}...
, as the last quarter of the fiscal year with the above configuration would be from 2015-05-31 to 2015-08-29.
"first week of 2016"
should parse to {"value":"2015-08-30T00:00:00.000-07:00","grain":"week","type":"value"}
I am thinking of the system returning always the value from the ISO calendar, but assuming the fiscal calendar in the natural language text.
A good reference for this type of calendar is this implementation for java.time: http://www.threeten.org/threeten-extra/.
Hi @tbaptista, thanks for providing the examples. At a quick glance, it seems like this could be implemented on top of assumptions (#29).
I disagree that this needs something as powerful as assumptions. When I hear "the last quarter of 2020", I immediately know the context (financial quarter). So I think we could definitely do something like
ruleFinancialQuarter :: Rule
ruleFinancialQuarter = Rule
{ name = "financial quarter"
, pattern =
[ regex "(last|previous|prior|current|next|upcoming) (financial)? quarter"
]
, prod = \case
(Token RegexMatch (GroupMatch (relative:_)):_) -> do
...case on relative...
_ -> Nothing
}
ruleFinancialQuarterOf :: Rule
ruleFinancialQuarterOf = Rule
{ name = "financial quarter of"
, pattern =
[ regex "(last|previous|prior|current|next|upcoming) (financial)? quarter (of|in)"
, isGrainOfTime Year
]
, prod = \case
...case on relative and provide the year...
}
It seems that all of the date calculations are assuming the ISO 8601 calendar (at least for the EN language). It would be interesting to be able to use other calendars, such as the fiscal calendar used by companies in the US (see https://en.wikipedia.org/wiki/Fiscal_year and https://en.wikipedia.org/wiki/4–4–5_calendar).
I am using duckling in a project where such an issue has arisen, and the best solution would be to support it in duckling.
As I understand, the support for this may need first #29 to be complete.