facebook / duckling

Language, engine, and tooling for expressing, testing, and evaluating composable language rules on input strings.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ne dimension is not working.

sbilgil opened this issue · comments

I added new dimension as citizen number for turkish Id. I created its own directory as phone-number or CreditCard dimension. I adde types and rules.hs files. I also add necessary code parts to other files like duckling.cabal, duckling/dimensions.hs, duckling/types.hs, duckling/dimensions/common.hs, duckling/dimensions/types.hs, duckling/rules/common.hs, duckling/rules/tr.hs. But when i send a request it cannot find it. I put very simple regex in it as a rule. It seems isnt working? Does any other request i need from github? Cant i add new dimension like this? Here are my types.hs and rules.hs files:

Types.hs:
`-- Copyright (c) 2016-present, Softtech, A.Ş.
-- 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.

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NoRebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}

module Duckling.CitizenNumber.Types where

import Control.DeepSeq
import Data.Aeson
import Data.Hashable (Hashable)
import Data.Text (Text)
import qualified Data.Text as Text
import GHC.Generics (Generic)

import Prelude

import Duckling.Resolve (Resolve(..))

data CitizenNumberData = CitizenNumberData
{ number :: Text
}
deriving (Eq, Ord, Show, Generic, Hashable, NFData)

instance Resolve CitizenNumberData where
type ResolvedValue CitizenNumberData = CitizenNumberValue
resolve _ _ CitizenNumberData {number} =
Just (CitizenNumberValue number, False)

data CitizenNumberValue = CitizenNumberValue
{ vNumber :: Text
}
deriving (Eq, Ord, Show)

instance ToJSON CitizenNumberValue where
toJSON (CitizenNumberValue number) =
object [ "value" .= number
]
`

Rules.hs :

`-- Copyright (c) 2024-present, [Your Name]
-- 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.

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NoRebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

module Duckling.CitizenNumber.Rules
( rules ) where

import Prelude
import Data.String
import Data.Text (Text)
import Data.Bool
import qualified Data.Text as T
import qualified Data.Char as C
import Debug.Trace

import Duckling.Dimensions.Types
import Duckling.Regex.Types
import Duckling.Types
import Duckling.CitizenNumber.Types (CitizenNumberData(..))

rules :: [Rule]
rules =
[ turkishCitizenNumberRule1 ]

turkishCitizenNumberRule1 :: Rule
turkishCitizenNumberRule1 = Rule
{ name = "turkish citizen number regex 1"
, pattern = [regex "[1-9]"]
, prod = \case
(Token RegexMatch (GroupMatch (g:_)) : _) ->
trace ("Matched with pattern1: " ) $
Just . Token CitizenNumber $ CitizenNumberData g
_ ->
trace ("not Matched with pattern2: " ) $
Nothing
}
`

I succeeded to make it working.