mirror of
https://github.com/facebook/duckling.git
synced 2024-08-17 17:20:55 +03:00
In Debug.hs, s/sentence/input/g
Summary: When tracing the code from Debug downward, the unnecessary rename of an argument from `sentence` to `input` creates a context switch. Let's use the same name throughout. Reviewed By: chessai Differential Revision: D28213244 fbshipit-source-id: 22476d958312e5c60cd32ff1e3d0d460cf0c8c79
This commit is contained in:
parent
a88b70feb7
commit
ce3614fedd
@ -40,35 +40,35 @@ debug :: Locale -> Text -> [Seal Dimension] -> IO [Entity]
|
||||
debug locale = debugCustom testContext {locale = locale} testOptions
|
||||
|
||||
allParses :: Locale -> Text -> [Seal Dimension] -> IO [Entity]
|
||||
allParses l sentence targets = debugTokens sentence $ parses l sentence targets
|
||||
allParses l input targets = debugTokens input $ parses l input targets
|
||||
|
||||
fullParses :: Locale -> Text -> [Seal Dimension] -> IO [Entity]
|
||||
fullParses l sentence targets =
|
||||
fullParses l input targets =
|
||||
debugTokens
|
||||
sentence
|
||||
input
|
||||
$ filter
|
||||
(\Resolved{range = Range start end} -> start == 0 && end == n)
|
||||
$ parses l sentence targets
|
||||
$ parses l input targets
|
||||
where
|
||||
n = Text.length sentence
|
||||
n = Text.length input
|
||||
|
||||
debugCustom :: Context -> Options -> Text -> [Seal Dimension] -> IO [Entity]
|
||||
debugCustom context options sentence targets =
|
||||
debugCustom context options input targets =
|
||||
debugTokens
|
||||
sentence
|
||||
$ analyze sentence context options $ HashSet.fromList targets
|
||||
input
|
||||
$ analyze input context options $ HashSet.fromList targets
|
||||
|
||||
ptree :: Text -> Entity -> IO ()
|
||||
ptree sentence Entity {enode} = pnode sentence 0 enode
|
||||
ptree input Entity {enode} = pnode input 0 enode
|
||||
|
||||
-- -----------------------------------------------------------------
|
||||
-- Internals
|
||||
|
||||
parses :: Locale -> Text -> [Seal Dimension] -> [ResolvedToken]
|
||||
parses l sentence targets =
|
||||
parses l input targets =
|
||||
filter isRelevantDimension tokens
|
||||
where
|
||||
tokens = parseAndResolve rules sentence testContext {locale = l} testOptions
|
||||
tokens = parseAndResolve rules input testContext {locale = l} testOptions
|
||||
rules = rulesFor l $ HashSet.fromList targets
|
||||
isRelevantDimension Resolved{node = Node{token = (Token d _)}} =
|
||||
case targets of
|
||||
@ -76,16 +76,16 @@ parses l sentence targets =
|
||||
_ -> elem (Seal d) targets
|
||||
|
||||
debugTokens :: Text -> [ResolvedToken] -> IO [Entity]
|
||||
debugTokens sentence tokens = do
|
||||
mapM_ (ptree sentence) entities
|
||||
debugTokens input tokens = do
|
||||
mapM_ (ptree input) entities
|
||||
return entities
|
||||
where entities = map (formatToken sentence) tokens
|
||||
where entities = map (formatToken input) tokens
|
||||
|
||||
pnode :: Text -> Int -> Node -> IO ()
|
||||
pnode sentence depth Node {children, rule, nodeRange = Range start end} = do
|
||||
pnode input depth Node {children, rule, nodeRange = Range start end} = do
|
||||
Text.putStrLn out
|
||||
mapM_ (pnode sentence (depth + 1)) children
|
||||
mapM_ (pnode input (depth + 1)) children
|
||||
where
|
||||
out = Text.concat [ Text.replicate depth "-- ", name, " (", body, ")" ]
|
||||
name = fromMaybe "regex" rule
|
||||
body = Text.drop start $ Text.take end sentence
|
||||
body = Text.drop start $ Text.take end input
|
||||
|
Loading…
Reference in New Issue
Block a user