2017-03-08 21:33:55 +03:00
|
|
|
-- Copyright (c) 2016-present, Facebook, Inc.
|
|
|
|
-- All rights reserved.
|
|
|
|
--
|
|
|
|
-- This source code is licensed under the BSD-style license found in the
|
|
|
|
-- LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
-- of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
|
|
|
|
|
|
|
{-# LANGUAGE GADTs #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
module Duckling.Distance.KO.Rules
|
|
|
|
( rules ) where
|
|
|
|
|
|
|
|
import Data.String
|
|
|
|
import Prelude
|
|
|
|
|
|
|
|
import Duckling.Dimensions.Types
|
|
|
|
import Duckling.Distance.Helpers
|
|
|
|
import qualified Duckling.Distance.Types as TDistance
|
2017-03-16 23:42:15 +03:00
|
|
|
import Duckling.Numeral.Types (NumeralData (..))
|
|
|
|
import qualified Duckling.Numeral.Types as TNumeral
|
2017-03-08 21:33:55 +03:00
|
|
|
import Duckling.Types
|
|
|
|
|
|
|
|
ruleLatentDistYard :: Rule
|
|
|
|
ruleLatentDistYard = Rule
|
|
|
|
{ name = "<latent dist> yard"
|
|
|
|
, pattern =
|
|
|
|
[ dimension Distance
|
2017-09-07 22:33:31 +03:00
|
|
|
, regex "y(ar)?ds?|야드"
|
2017-03-08 21:33:55 +03:00
|
|
|
]
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
(Token Distance dd:_) ->
|
|
|
|
Just . Token Distance $ withUnit TDistance.Yard dd
|
|
|
|
_ -> Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
ruleDistCentimeters :: Rule
|
|
|
|
ruleDistCentimeters = Rule
|
|
|
|
{ name = "<dist> centimeters"
|
|
|
|
, pattern =
|
|
|
|
[ dimension Distance
|
2017-09-07 22:33:31 +03:00
|
|
|
, regex "cm|센(티|치)((미|메)터)?"
|
2017-03-08 21:33:55 +03:00
|
|
|
]
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
(Token Distance dd:_) ->
|
|
|
|
Just . Token Distance $ withUnit TDistance.Centimetre dd
|
|
|
|
_ -> Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
ruleLatentDistFeetAndLatentDistInch :: Rule
|
|
|
|
ruleLatentDistFeetAndLatentDistInch = Rule
|
|
|
|
{ name = "<latent dist> feet and <latent dist> inch "
|
|
|
|
, pattern =
|
|
|
|
[ dimension Distance
|
2017-09-07 22:33:31 +03:00
|
|
|
, regex "('|f(oo|ee)?ts?)|피트"
|
2017-03-08 21:33:55 +03:00
|
|
|
, dimension Distance
|
2017-09-07 22:33:31 +03:00
|
|
|
, regex "(''|inch(es)?)|인치"
|
2017-03-08 21:33:55 +03:00
|
|
|
]
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
(Token Distance dd:_) ->
|
|
|
|
Just . Token Distance $ withUnit TDistance.Foot dd
|
|
|
|
_ -> Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
ruleDistMeters :: Rule
|
|
|
|
ruleDistMeters = Rule
|
|
|
|
{ name = "<dist> meters"
|
|
|
|
, pattern =
|
|
|
|
[ dimension Distance
|
2017-09-07 22:33:31 +03:00
|
|
|
, regex "m|(미|메|매)터"
|
2017-03-08 21:33:55 +03:00
|
|
|
]
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
(Token Distance dd:_) ->
|
|
|
|
Just . Token Distance $ withUnit TDistance.Metre dd
|
|
|
|
_ -> Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
ruleLatentDistFeet :: Rule
|
|
|
|
ruleLatentDistFeet = Rule
|
|
|
|
{ name = "<latent dist> feet"
|
|
|
|
, pattern =
|
|
|
|
[ dimension Distance
|
2017-09-07 22:33:31 +03:00
|
|
|
, regex "('|f(oo|ee)?ts?)|피트"
|
2017-03-08 21:33:55 +03:00
|
|
|
]
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
(Token Distance dd:_) ->
|
|
|
|
Just . Token Distance $ withUnit TDistance.Foot dd
|
|
|
|
_ -> Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
ruleLatentDistKm :: Rule
|
|
|
|
ruleLatentDistKm = Rule
|
|
|
|
{ name = "<latent dist> km"
|
|
|
|
, pattern =
|
|
|
|
[ dimension Distance
|
2017-09-07 22:33:31 +03:00
|
|
|
, regex "km|(킬|키)로((미|메)터)?"
|
2017-03-08 21:33:55 +03:00
|
|
|
]
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
(Token Distance dd:_) ->
|
|
|
|
Just . Token Distance $ withUnit TDistance.Kilometre dd
|
|
|
|
_ -> Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
ruleHalf :: Rule
|
|
|
|
ruleHalf = Rule
|
|
|
|
{ name = "half"
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
[ regex "반"
|
2017-03-08 21:33:55 +03:00
|
|
|
]
|
|
|
|
, prod = \tokens -> case tokens of
|
2017-03-16 23:42:15 +03:00
|
|
|
(Token Numeral NumeralData {TNumeral.value = v}:_) ->
|
2017-03-08 21:33:55 +03:00
|
|
|
Just . Token Distance $ distance v
|
|
|
|
_ -> Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
ruleDistMiles :: Rule
|
|
|
|
ruleDistMiles = Rule
|
|
|
|
{ name = "<dist> miles"
|
|
|
|
, pattern =
|
|
|
|
[ dimension Distance
|
2017-09-07 22:33:31 +03:00
|
|
|
, regex "miles?|마일(즈)?"
|
2017-03-08 21:33:55 +03:00
|
|
|
]
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
(Token Distance dd:_) ->
|
|
|
|
Just . Token Distance $ withUnit TDistance.Mile dd
|
|
|
|
_ -> Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
ruleLatentDistInch :: Rule
|
|
|
|
ruleLatentDistInch = Rule
|
|
|
|
{ name = "<latent dist> inch"
|
|
|
|
, pattern =
|
|
|
|
[ dimension Distance
|
2017-09-07 22:33:31 +03:00
|
|
|
, regex "(''|inch(es)?)|인치"
|
2017-03-08 21:33:55 +03:00
|
|
|
]
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
(Token Distance dd:_) ->
|
|
|
|
Just . Token Distance $ withUnit TDistance.Inch dd
|
|
|
|
_ -> Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
rules :: [Rule]
|
|
|
|
rules =
|
|
|
|
[ ruleDistCentimeters
|
|
|
|
, ruleDistMeters
|
|
|
|
, ruleDistMiles
|
|
|
|
, ruleHalf
|
|
|
|
, ruleLatentDistFeet
|
|
|
|
, ruleLatentDistFeetAndLatentDistInch
|
|
|
|
, ruleLatentDistInch
|
|
|
|
, ruleLatentDistKm
|
|
|
|
, ruleLatentDistYard
|
|
|
|
]
|