From ba4057b214c4a655064133b07f5a4428a69f4252 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Mon, 21 May 2018 09:10:19 +0200 Subject: [PATCH 1/6] Missing -I in Java bindings Makefile --- src/runtime/java/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/java/Makefile b/src/runtime/java/Makefile index b7a7264cc..02083ddac 100644 --- a/src/runtime/java/Makefile +++ b/src/runtime/java/Makefile @@ -3,7 +3,7 @@ JAVA_SOURCES = $(wildcard org/grammaticalframework/pgf/*.java) \ $(wildcard org/grammaticalframework/sg/*.java) JNI_INCLUDES = $(if $(wildcard /usr/lib/jvm/default-java/include/.*), -I/usr/lib/jvm/default-java/include -I/usr/lib/jvm/default-java/include/linux, \ - $(if $(wildcard /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/.*), /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers, \ + $(if $(wildcard /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/.*), -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers, \ $(if $(wildcard /Library/Java/Home/include/.*), -I/Library/Java/Home/include/ -I/Library/Java/Home/include/darwin, \ $(error No JNI headers found)))) From 41af91f6978f97e667c6f3453e219f7492c608db Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Mon, 21 May 2018 09:14:26 +0200 Subject: [PATCH 2/6] Update info about path to jni.h in Java binding install notes --- src/runtime/java/INSTALL | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/runtime/java/INSTALL b/src/runtime/java/INSTALL index 6d97dd279..c0e91a355 100644 --- a/src/runtime/java/INSTALL +++ b/src/runtime/java/INSTALL @@ -1,10 +1,12 @@ -Before compiling the Java binding you first need to have the C runtime +Before compiling the Java binding you first need to have the C runtime compiled and installed. You also need to find where your jni.h header is installed. It is part of the Java JDK, but it might be placed -in different places on different platforms. The path to the jni.h -header should be assigned to the JNI_PATH variable in the beginning -of the Makefile that you will find in the root directory of -the binding. Once this is done type: +in different places on different platforms. +The Makefile in this directory will try to figure out the location of +jni.h, but if it doesn't succeed you should add it manually to the +JNI_INCLUDES variable in the beginning of the Makefile. + +Once this is done type: $ make $ make install From a6779486c55d3d61637edec135b897a724cb9d2d Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Mon, 21 May 2018 09:36:39 +0200 Subject: [PATCH 3/6] fix the compilation when the byte order cannot be detected statically --- src/runtime/c/sg/sqlite3Btree.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/runtime/c/sg/sqlite3Btree.c b/src/runtime/c/sg/sqlite3Btree.c index a75cfd62b..ee6bd206a 100644 --- a/src/runtime/c/sg/sqlite3Btree.c +++ b/src/runtime/c/sg/sqlite3Btree.c @@ -4918,6 +4918,7 @@ SQLITE_PRIVATE int sqlite3PendingByte; # define SQLITE_UTF16NATIVE SQLITE_UTF16BE #endif #if !defined(SQLITE_BYTEORDER) +const int sqlite3one = 1; # define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */ # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) From 9d39648dfba3b2565e89b2de3a8a6db90ade6aaf Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Mon, 21 May 2018 16:03:30 +0200 Subject: [PATCH 4/6] fixed typo which broke the compilation on Windows --- src/runtime/c/Makefile.am | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/runtime/c/Makefile.am b/src/runtime/c/Makefile.am index edc4f88b2..8f9c8bf56 100644 --- a/src/runtime/c/Makefile.am +++ b/src/runtime/c/Makefile.am @@ -87,13 +87,14 @@ libpgf_la_SOURCES = \ pgf/graphviz.c \ pgf/aligner.c \ pgf/pgf.c \ - pgf/pgf.h \ -libpgf_la_LDFLAGS = "-no-undefined" + pgf/pgf.h +libpgf_la_LDFLAGS = -no-undefined libpgf_la_LIBADD = libgu.la libsg_la_SOURCES = \ sg/sqlite3Btree.c \ sg/sg.c +libsg_la_LDFLAGS = -no-undefined libsg_la_LIBADD = libgu.la libpgf.la bin_PROGRAMS = From b635cb3d5208478097b5dfd8e2476aef857e96c9 Mon Sep 17 00:00:00 2001 From: Inari Listenmaa Date: Mon, 21 May 2018 18:41:16 +0100 Subject: [PATCH 5/6] (gftest) Better pruning + add new command line option --- src/tools/gftest/Grammar.hs | 74 ++++++++++++++++++++++++------------- src/tools/gftest/Main.hs | 11 +++++- src/tools/gftest/README.md | 16 ++++++++ 3 files changed, 75 insertions(+), 26 deletions(-) diff --git a/src/tools/gftest/Grammar.hs b/src/tools/gftest/Grammar.hs index f8333e78b..f8c507acd 100644 --- a/src/tools/gftest/Grammar.hs +++ b/src/tools/gftest/Grammar.hs @@ -931,7 +931,8 @@ data Comparison = Comparison { funTree :: String, linTree :: [LinTree] } instance Show Comparison where show c = unlines $ funTree c : map showLinTree (linTree c) -dummyHole = App (Symbol "∅" [] ([], "") ([], CC Nothing 99999999)) [] +dummyCCat = CC Nothing 99999999 +dummyHole = App (Symbol "∅" [] ([], "") ([], dummyCCat)) [] showLinTree :: LinTree -> String showLinTree ((an,hl),(l1,t1),(l2,t2),(_l,[])) = unlines ["", an++hl, l1++t1, l2++t2] @@ -967,42 +968,65 @@ testFun :: Bool -> Grammar -> [Grammar] -> Cat -> Name -> Result testFun debug gr trans startcat funname = let test = testTree debug gr trans in unlines [ test t n cs - | (n,(t,cs)) <- zip [1..] trees_Ctxs ] + | (n,(t,cs)) <- zip [1..] testcase_ctxs ] where - trees_Ctxs = [ (t,commonCtxs) | t <- reducedTrees - , not $ null commonCtxs ] ++ - [ (t,uniqueCtxs) | t <- allTrees - , not $ null uniqueCtxs ] + testcase_ctxs = M.toList $ M.fromListWith (++) $ uniqueTCs++commonTCs + uniqueTCs = [ (testcase,uniqueCtxs) + | (testcase,ctxs) <- M.elems cat_testcase_ctxs + , let uniqueCtxs = deleteFirstsBy applyHole ctxs commonCtxs + , not $ null uniqueCtxs + ] + commonTCs = [ (App newTop subtrees,ctxs) + | (coe,cats,ctxs) <- coercion_goalcats_commonCtxs + , let testcases_ctxs = catMaybes [ M.lookup cat cat_testcase_ctxs + | cat <- cats ] + , not $ null testcases_ctxs + , let fstLen = \(a,_) (b,_) -> length (flatten a) `compare` length (flatten b) + , let (App tp subtrees,_) = -- pick smallest test case to be the representative + head $ sortBy fstLen testcases_ctxs + , let newTop = -- debug: put coerced contexts under a separate test case + if debug then tp { ctyp = (fst $ ctyp tp, coe)} else tp + ] + + -- Usually start category is a single {s:Str}, i.e. only one concrete category. + -- If you try this out for start categories with more parameters and fields, + -- you probably get wrong or missing results. (start:_) = ccats gr startcat + hl f c1 c2 = f (c1 dummyHole) == f (c2 dummyHole) -- applyHole = hl id -- TODO why doesn't this work for equality of contexts? applyHole = hl show -- :: (Tree -> Tree) -> (Tree -> Tree) -> Bool - goalcats = map ccatOf allTrees :: [ConcrCat] -- these are not coercions (coercions can't be goals) - - coercionsThatCoverAllGoalcats = [ (c,fs) - | (c,fs) <- contexts gr start - , all (coerces gr c) goalcats ] funs = case lookupSymbol gr funname of [] -> error $ "Function "++funname++" not found" fs -> fs - allTrees = treesUsingFun gr funs - ctxs = nubBy applyHole $ concatMap (contextsFor gr start) goalcats :: [Tree->Tree] - (commonCtxs,reducedTrees) = case coercionsThatCoverAllGoalcats of - [] -> ([],[]) -- no coercion covers all goal cats -> all contexts are relevant - cs -> (cCtxs,rTrees) -- all goal cats coerce into same -> find redundant contexts - where - (coe,coercedCtxs) = head coercionsThatCoverAllGoalcats - cCtxs = intersectBy applyHole ctxs coercedCtxs - rTrees = concat $ bestExamples (head funs) gr - [ [ App newTop subtrees ] - | (App tp subtrees) <- allTrees - , let newTop = tp { ctyp = (fst $ ctyp tp, coe)} ] - uniqueCtxs = deleteFirstsBy applyHole ctxs commonCtxs - showCtx f = let t = f dummyHole in show t ++ "\t\t\t" ++ showConcrFun gr (top t) + cat_testcase_ctxs = M.fromList + [ (goalcat,(testcase,ctxs)) + | testcase <- treesUsingFun gr funs + , let goalcat = ccatOf testcase -- never a coercion (coercions can't be goals) + , let ctxs = contextsFor gr start goalcat ] :: M.Map ConcrCat (Tree,[Tree->Tree]) + goalcats = M.keys cat_testcase_ctxs + + coercion_goalcats_commonCtxs = + [ (coe,coveredGoalcats,ctxs) + | coe@(CC Nothing _) <- S.toList $ nonEmptyCats gr -- only coercions + , let coveredGoalcats = filter (coerces gr coe) goalcats + , let ctxs = [ ctx -- Contexts that have + | ctx <- contextsFor gr start coe -- a) hole of coercion, and are + , any (applyHole ctx) allCtxs ] -- b) relevant for the function we test + , length coveredGoalcats >= 2 -- no use if the coercion covers 0 or 1 categories + , not $ null ctxs ] + + + allCtxs = [ ctx | (_,ctxs) <- M.elems cat_testcase_ctxs + , ctx <- ctxs ] :: [Tree->Tree] + + commonCtxs = nubBy applyHole [ ctx | (_,_,ctxs) <- coercion_goalcats_commonCtxs + , ctx <- ctxs ] :: [Tree->Tree] + testTree :: Bool -> Grammar -> [Grammar] -> Tree -> Int -> [Tree -> Tree] -> Result testTree debug gr tgrs t n ctxs = unlines diff --git a/src/tools/gftest/Main.hs b/src/tools/gftest/Main.hs index fcabb33c3..afcf17830 100644 --- a/src/tools/gftest/Main.hs +++ b/src/tools/gftest/Main.hs @@ -30,6 +30,7 @@ data GfTest , start_cat :: Maybe Cat , show_cats :: Bool , show_funs :: Bool + , funs_of_arity :: Maybe Int , show_coercions:: Bool , concr_string :: String @@ -57,7 +58,8 @@ gftest = GfTest &= help "Concrete syntax + optional translations" , tree = def &= A.typ "\"UseN tree_N\"" &= A.name "t" &= help "Test the given tree" - , function = def &= A.typ "UseN" &= help "Test the given function(s)" + , function = def &= A.typ "UseN" + &= A.name "f" &= help "Test the given function(s)" , category = def &= A.typ "NP" &= A.name "c" &= help "Test all functions with given goal category" , start_cat = def &= A.typ "Utt" @@ -65,6 +67,7 @@ gftest = GfTest , concr_string = def &= A.typ "the" &= help "Show all functions that include given string" , show_cats = def &= help "Show all available categories" , show_funs = def &= help "Show all available functions" + , funs_of_arity = def &= A.typ "2" &= help "Show all functions of arity 2" , show_coercions= def &= help "Show coercions in the grammar" , debug = def &= help "Show debug output" , equal_fields = def &= A.name "q" &= help "Show fields whose strings are always identical" @@ -184,6 +187,12 @@ main = do putStrLn "* Coercions in the grammar:" putStrLn $ unlines [ show cat++"--->"++show coe | (cat,coe) <- coercions gr ] + case funs_of_arity args of + Nothing -> return () + Just n -> do + putStrLn $ "* Functions in the grammar of arity " ++ show n ++ ":" + putStrLn $ unlines $ nub [ show s | s <- symbols gr, arity s == n ] + -- Show all functions that contain the given string -- (e.g. English "it" appears in DefArt, ImpersCl, it_Pron, …) case concr_string args of diff --git a/src/tools/gftest/README.md b/src/tools/gftest/README.md index a71017004..5134300fd 100644 --- a/src/tools/gftest/README.md +++ b/src/tools/gftest/README.md @@ -69,6 +69,7 @@ Common flags: -s --start-cat=Utt Use the given category as start category --show-cats Show all available categories --show-funs Show all available functions + --funs-of-arity=2 Show all functions of arity 2 --show-coercions Show coercions in the grammar --concr-string=the Show all functions that include given string -q --equal-fields Show fields whose strings are always identical @@ -428,3 +429,18 @@ For example: * AdAdv very_AdA (PositAdvAdj young_A) * PrepNP above_Prep (UsePron they_Pron) ``` + +### --funs-of-arity + +Show all functions of given arity (not up to). + +Example: + +``` +> gftest -g Phrasebook --funs-of-arity 3 +* Functions in the grammar of arity 3: +ADoVerbPhrasePlace +AModVerbPhrase +HowFarFromBy +QWhereModVerbPhrase +``` From 10df5a7269721ab0807ec7a0fe4b75cd1bb16d87 Mon Sep 17 00:00:00 2001 From: Inari Listenmaa Date: Tue, 22 May 2018 11:49:42 +0100 Subject: [PATCH 6/6] (gftest) Multiple concrete categories for context generation --- src/tools/gftest/Grammar.hs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/tools/gftest/Grammar.hs b/src/tools/gftest/Grammar.hs index f8c507acd..4e6d0c6e9 100644 --- a/src/tools/gftest/Grammar.hs +++ b/src/tools/gftest/Grammar.hs @@ -990,10 +990,7 @@ testFun debug gr trans startcat funname = if debug then tp { ctyp = (fst $ ctyp tp, coe)} else tp ] - -- Usually start category is a single {s:Str}, i.e. only one concrete category. - -- If you try this out for start categories with more parameters and fields, - -- you probably get wrong or missing results. - (start:_) = ccats gr startcat + starts = ccats gr startcat hl f c1 c2 = f (c1 dummyHole) == f (c2 dummyHole) -- applyHole = hl id -- TODO why doesn't this work for equality of contexts? @@ -1007,16 +1004,18 @@ testFun debug gr trans startcat funname = [ (goalcat,(testcase,ctxs)) | testcase <- treesUsingFun gr funs , let goalcat = ccatOf testcase -- never a coercion (coercions can't be goals) - , let ctxs = contextsFor gr start goalcat ] :: M.Map ConcrCat (Tree,[Tree->Tree]) + , let ctxs = [ ctx | st <- starts + , ctx <- contextsFor gr st goalcat ] + ] :: M.Map ConcrCat (Tree,[Tree->Tree]) goalcats = M.keys cat_testcase_ctxs coercion_goalcats_commonCtxs = [ (coe,coveredGoalcats,ctxs) | coe@(CC Nothing _) <- S.toList $ nonEmptyCats gr -- only coercions , let coveredGoalcats = filter (coerces gr coe) goalcats - , let ctxs = [ ctx -- Contexts that have - | ctx <- contextsFor gr start coe -- a) hole of coercion, and are - , any (applyHole ctx) allCtxs ] -- b) relevant for the function we test + , let ctxs = [ ctx | st <- starts -- Contexts that have + , ctx <- contextsFor gr st coe -- a) hole of coercion, and are + , any (applyHole ctx) allCtxs ] -- b) relevant for the function we test , length coveredGoalcats >= 2 -- no use if the coercion covers 0 or 1 categories , not $ null ctxs ]