Commit Graph

17 Commits

Author SHA1 Message Date
chessai
99e1dce9c4 restrict dimensions to only those specified (#625)
Summary:
Resolves https://github.com/facebook/duckling/issues/624

Before patch (specifying quantity and numeral, but time still shows up):
```
❯ curl -XPOST http://0.0.0.0:8000/parse --data 'locale=en_US&text="June 21 and 3 cups of sugar"&dims="[\"quantity\",\"numeral\"]"' | jq
[
  {
    "body": "June 21",
    "start": 1,
    "value": {
      "values": [
        {
          "value": "2021-06-21T00:00:00.000-07:00",
          "grain": "day",
          "type": "value"
        },
        {
          "value": "2022-06-21T00:00:00.000-07:00",
          "grain": "day",
          "type": "value"
        },
        {
          "value": "2023-06-21T00:00:00.000-07:00",
          "grain": "day",
          "type": "value"
        }
      ],
      "value": "2021-06-21T00:00:00.000-07:00",
      "grain": "day",
      "type": "value"
    },
    "end": 8,
    "dim": "time",
    "latent": false
  },
  {
    "body": "3 cups of sugar",
    "start": 13,
    "value": {
      "value": 3,
      "type": "value",
      "product": "sugar",
      "unit": "cup"
    },
    "end": 28,
    "dim": "quantity",
    "latent": false
  }
]
```

After patch (time no longer shows up):
```
❯ curl -XPOST http://0.0.0.0:8000/parse --data 'locale=en_US&text="June 21 and 3 cups of sugar"&dims="[\"quantity\",\"numeral\"]"' | jq
[
  {
    "body": "3 cups of sugar",
    "start": 13,
    "value": {
      "value": 3,
      "type": "value",
      "product": "sugar",
      "unit": "cup"
    },
    "end": 28,
    "dim": "quantity",
    "latent": false
  }
]
```

Pull Request resolved: https://github.com/facebook/duckling/pull/625

Reviewed By: stroxler

Differential Revision: D28851759

Pulled By: chessai

fbshipit-source-id: d3b3f33092c7e60bf29886939488ed562a213c35
2021-06-03 10:33:42 -07:00
Steven Troxler
0efbfe5988 Give a usable error if we fail to parse reftime parameter
Summary:
My attention was brought to this issue by the linter complaining about `read`.

The linter is just as happy with `error`, but I do think it's better to fail
with a usable error message here than with whatever error `read` gives us.

Reviewed By: chessai

Differential Revision: D28213406

fbshipit-source-id: f101d0515ee64978480bdbb873ff72d80d124969
2021-05-07 06:20:03 -07:00
Steven Troxler
eba5d0a825 Simple style fixes for outer layers around Engine.hs
Summary:
Easy style fixes for ExampleMain.hs, Debug.hs, Api.hs, Core.hs

Most of these are just lint fixes, but I also made a few not-just-lint changes
to conform to some elements of our style guide that I agree with:
- if the type signature doesn't fit on one line, then put one type per line
  with nothing on the first line, so that all types are vertically aligned - makes
  for a quick skim
- try to avoid mixing same-line function args with hanging function args: hang
  all arguments or none at all to get a more outline-like feel, again better for
  skimming

I was actually able to eliminate all errors for most of these modules - the name
collisions I usually give up on were manageable by hiding + easy variable renames

Reviewed By: chessai

Differential Revision: D28213246

fbshipit-source-id: 1f77d56f2ff8dccfd5f3b534f087c07047b92885
2021-05-06 08:54:56 -07:00
chessai
8de488475a Load timezones more leniently. (#582)
Summary:
On some linux systems, such as on NixOS, /usr/share/zoneinfo does not
exist. What does exist in its place is /etc/zoneinfo. So, we should try to load
that if /usr/share/zoneinfo does not exist.

Pull Request resolved: https://github.com/facebook/duckling/pull/582

Reviewed By: girifb

Differential Revision: D27086925

Pulled By: chessai

fbshipit-source-id: f4a38822be9888d57034f67a6f7abd17d56d38b8
2021-03-16 13:04:09 -07:00
Tobias Wochinger
97636f525e skip logfile creation if no logging (#377)
Summary:
**Motivation**
Currently the log files and the log directory for the server are always created, even if the logging is disabled. If duckling is used on OpenShift the file creation leads to errors if no volume mount is defined.

**Proposed Change**:
Only create log files / log directory if the logging is enabled.

Pull Request resolved: https://github.com/facebook/duckling/pull/377

Reviewed By: patapizza

Differential Revision: D26148878

Pulled By: chessai

fbshipit-source-id: f8e2b1a38586121d854a4826c322b4b859cc9c6b
2021-01-29 11:32:32 -08:00
chessai
a319da07b2 ExampleMain: fix build failure (#560)
Summary: Pull Request resolved: https://github.com/facebook/duckling/pull/560

Reviewed By: patapizza

Differential Revision: D25564850

Pulled By: chessai

fbshipit-source-id: 631f96a3ed71b9d7707560ff6bfe7596feee2305
2020-12-15 11:48:04 -08:00
Daniel Cartwright
17f11135f2 Document how to pass dimensions to the example application
Summary: External users are repeatedly confused by lack of results from the duckling example executable. We should just go through all dimensions for the duckling call in the example app.

Reviewed By: patapizza

Differential Revision: D25468199

fbshipit-source-id: 6cf56b130d4d0aa3181f098d6a7c9a133bfa85ff
2020-12-14 15:02:37 -08:00
Josef Svenningsson
7889f396f3 Remove dependency on Data.Some (#533)
Summary:
Pull Request resolved: https://github.com/facebook/duckling/pull/533

In recent versions of Data.Some the name of the constructor, `This` has changed name to `Some`. This has become rather problematic for us to migrate so we're just going to remove the dependency. The meat of this diff is adding the type `Seal` to `Duckling.Types`. That type replaces `Some`.

Reviewed By: pepeiborra

Differential Revision: D23929459

fbshipit-source-id: 8ff4146ecba4f1119a17899961b2d877547f6e4f
2020-09-28 01:33:01 -07:00
Julien Odent
bf89e34365 Relicense to BSD3
Reviewed By: JoelMarcey

Differential Revision: D15439223

fbshipit-source-id: c5af3cb06318748142fe503945b38beffadfc28a
2019-05-22 10:46:39 -07:00
Martin Heuschober
36eda02097 add support for setting the port (#281)
Summary:
+ based on https://stackoverflow.com/a/51671356/630160 I have implemented:
    - passing in `--port=8080`
    - or setting PORT=8080 as environment variable
  where  `default < PORT < --port`, i.e. a --port parameter overrides both an environment variable and a default value, and an environment variable PORT overrides the default value.

+ change small hlint: `fromMaybe def . fmap f = `maybe def f`
Pull Request resolved: https://github.com/facebook/duckling/pull/281

Differential Revision: D13388735

Pulled By: patapizza

fbshipit-source-id: cbc4a819036dbec474526b862b0f6187f02b6155
2018-12-12 11:15:52 -08:00
Julien Odent
f8c967c28d ExampleMain: show how to query for custom dimensions
Summary:
After including a custom dimension in `duckling.cabal` and importing
the constructor in `ExampleMain.hs`, you can query it using the `dims`
parameters (e.g. `dims=["my-dimension"]`).
Note that a custom dimension file should only expose the constructor (i.e.
`MyDimension(..)`) (and maybe a `corpus`).

https://github.com/facebook/duckling/issues/236

Reviewed By: adanielescu

Differential Revision: D9315608

fbshipit-source-id: 4908e7e27b31201c440a0c0db4cd3d567bd1e6f8
2018-08-16 15:30:43 -07:00
Chinmay Deshmukh
5ac990bbe2 Return latent entities
Summary: Add an option to return latent time entities. This can be used when one is pretty certain that the input contains a datetime.

Reviewed By: patapizza

Differential Revision: D7254245

fbshipit-source-id: e9e0503cace2691804056fcebdc18fd9090fb181
2018-03-19 14:45:27 -07:00
Panagiotis Vekris
f28ad7a367 support for reference time param in web server
Summary:
PR for the issue #132
Closes https://github.com/facebook/duckling/pull/133

Reviewed By: patapizza

Differential Revision: D6661000

Pulled By: panagosg7

fbshipit-source-id: da061cb55e86c8747ff885df9881e270d22cdfa7
2018-01-10 12:45:37 -08:00
Julien Odent
ab0ad0256e Locales support
Summary:
* Locales support for the library, following `<Lang>_<Region>` with ISO 639-1 code for `<Lang>` and ISO 3166-1 alpha-2 code for `<Region>` (#33)
* `Locale` opaque type (composite of `Lang` and `Region`) with `makeLocale` smart constructor to only allow valid `(Lang, Region)` combinations
* API: `Context`'s `lang` parameter has been replaced by `locale`, with optional `Region` and backward compatibility.
*  `Rules/<Lang>.hs` exposes
  - `langRules`: cross-locale rules for `<Lang>`, from `<Dimension>/<Lang>/Rules.hs`
  - `localeRules`: locale-specific rules, from `<Dimension>/<Lang>/<Region>/Rules.hs`
  - `defaultRules`: `langRules` + specific rules from select locales to ensure backward-compatibility
* Corpus, tests & classifiers
  - 1 classifier per locale, with default classifier (`<Lang>_XX`) when no locale provided (backward-compatible)
  - Default classifiers are built on existing corpus
  - Locale classifiers are built on
  - `<Dimension>/<Lang>/Corpus.hs` exposes a common `corpus` to all locales of `<Lang>`
  - `<Dimension>/<Lang>/<Region>/Corpus.hs` exposes `allExamples`: a list of examples specific to the locale (following `<Dimension>/<Lang>/<Region>/Rules.hs`).
  - Locale classifiers use the language corpus extended with the locale examples as training set.
  - Locale examples need to use the same `Context` (i.e. reference time) as the language corpus.
  - For backward compatibility, `<Dimension>/<Lang>/Corpus.hs` can expose also `defaultCorpus`, which is `corpus` augmented with specific examples. This is controlled by `getDefaultCorpusForLang` in `Duckling.Ranking.Generate`.
  - Tests run against each classifier to make sure runtime works as expected.
* MM/DD (en_US) vs DD/MM (en_GB) example to illustrate

Reviewed By: JonCoens, blandinw

Differential Revision: D6038096

fbshipit-source-id: f29c28d
2017-10-13 08:34:21 -07:00
Julien Odent
3ec2228eac Setup logs
Summary: Fixes #41

Reviewed By: niteria

Differential Revision: D5242794

fbshipit-source-id: cd53bd6
2017-06-14 02:04:26 -07:00
Jonathan Coens
b3ca32104d Simple example HTTP server
Summary: Runs a `snap` server to return the support targets as well as do parsing. It's a bit cludgy, but gets the job done.

Reviewed By: patapizza

Differential Revision: D4813197

fbshipit-source-id: 0fa165b
2017-04-06 17:04:48 -07:00
Bartosz Nitka
bd94622f64 Move tests to tests and exes to exe
Summary:
This works around https://github.com/haskell/cabal/issues/4350
If we don't do this files get compiled multiple times
and cabal is unhappy.

Reviewed By: patapizza

Differential Revision: D4782749

fbshipit-source-id: 5bbe425
2017-03-27 16:04:24 -07:00