Generating a sentence with passive tense in GF without "to be" - gf

I used Phrase to generate the sentence "Play a comedy movie hosted by BBC".
mkPhr (mkVP(
(mkV2 (mkV ("Play")))
(mkNP
aSg_Det
(mkCN
(mkCN (mkN ("comedy")))
(mkSC (passiveVP
(mkV2 ("host"))
(mkNP (mkN ("BBC"))))))))
But I get the result "Play a movie to be hosted by BBC". I checked GF librires but it seems like there is no way to change a VP to a NP in order to avoid "to be".
May you guys to teach me how to get rid of this to be, or is there any way in GF to add up two sentences or more to a Phrase.
Thank you~

Like #aschepler said, "hosted by BBC" is a participle phrase, not passive voice. In the Extend module, there are a couple of functions to create participles from VPs:
PastPartAP : VPSlash -> AP ; -- lost (opportunity) ; (opportunity) lost in space
PastPartAgentAP : VPSlash -> NP -> AP ; -- (opportunity) lost by the company
So we can use PastPartAgentAP to create the participle "hosted by BBC".
If you open ExtendEng in your GF file, you can use all of its functions, just like you're already doing with SyntaxEng and ParadigmsEng. (See also this answer.)
Here's an example that you can copy and paste into a file called Comedy.gf and play with it in the GF shell.
resource Comedy = open SyntaxEng, ParadigmsEng, ExtendEng in {
oper
-- Some lexicon
comedy_N : N = mkN "comedy" ;
host_V2 : V2 = mkV2 "host" ;
play_V2 : V2 = mkV2 "play" ;
BBC_PN : PN = mkPN "BBC" ;
-- Intermediate phrases
hosted_by_BBC : AP =
PastPartAgentAP (mkVPSlash host_V2) (mkNP BBC_PN) ;
comedy_hosted_by_BBC : NP =
mkNP a_Det (mkCN comedy_N hosted_by_BBC) ;
-- The final phrase
play_comedy_hosted_by_BBC : Utt =
mkUtt (mkImp (mkVP play_V2 comedy_hosted_by_BBC)) ;
}
When you open Comedy.gf in a GF shell with the flag -retain, you can check the lexicon and the intermediate results with the command cc. For example:
> cc -table comedy_hosted_by_BBC
s . NCase Nom => a comedy hosted by BBC
s . NCase Gen => a comedy's hosted by BBC
s . NPAcc => a comedy hosted by BBC
s . NPNomPoss => a comedy hosted by BBC
a . AgP3Sg Neutr
> cc -one play_comedy_hosted_by_BBC
play a comedy hosted by BBC

Related

How can I move filtered triples from one graph to other?

I am using jena-fuseki server. Suppose for example my default graph has the following triples.
#prefix bprefix: <http://raghav/Rathi#>
bprefix:title71 a bprefix:Title ;
bprefix:fromCountry bprefix:UnitedStates ;
bprefix:hasCast bprefix:BobbyMoynihan , bprefix:DemetriMartin , bprefix:EricEdelstein ;
bprefix:hasDateAdded "September 30, 2018" ;
bprefix:hasDescription "Grizzly, Panda and Ice Bear are three adopted bear brothers struggling against their animal instincts to fit into the civilized, modern human world." ;
bprefix:hasDuration "1 Season" ;
bprefix:hasID "80116921"^^xsd:int ;
bprefix:hasRating bprefix:TV-Y7 ;
bprefix:hasReleaseyear "2017"^^xsd:int ;
bprefix:hasTitle "We Bare Bears" ;
bprefix:hasType bprefix:TVShow ;
bprefix:isListedin bprefix:TVComedies , <http://raghav/Rathi#Kids'TV> .
bprefix:title84 a bprefix:Title ;
bprefix:fromCountry bprefix:UnitedKingdom ;
bprefix:hasCast bprefix:PaulHollywood ;
bprefix:hasDateAdded "September 29, 2017" ;
bprefix:hasDescription "Gear up for a fast-paced journey as celebrity chef and avid auto enthusiast Paul Hollywood takes in the cars and culture of France, Italy and Germany." ;
bprefix:hasDuration "1 Season" ;
bprefix:hasID "80199032"^^xsd:int ;
bprefix:hasRating bprefix:TV-14 ;
bprefix:hasReleaseyear "2014"^^xsd:int ;
bprefix:hasTitle "Paul Hollywood's Big Continental Road Trip" ;
bprefix:hasType bprefix:TVShow ;
bprefix:isListedin bprefix:BritishTVShows , bprefix:Docuseries , bprefix:InternationalTVShows .
bprefix:title28 a bprefix:Title ;
bprefix:fromCountry bprefix:UnitedStates ;
bprefix:hasDateAdded "September 7, 2018" ;
bprefix:hasDescription "Women whO ve been sexually brutalized in war-torn Congo begin to heal at City of Joy, a center that helps them regain a sense of self and empowerment." ;
bprefix:hasDirector bprefix:MadeleineGavin ;
bprefix:hasDuration "77 min" ;
bprefix:hasID "80203094"^^xsd:int ;
bprefix:hasRating bprefix:TV-MA ;
bprefix:hasReleaseyear "2018"^^xsd:int ;
bprefix:hasTitle "City of Joy" ;
bprefix:hasType bprefix:Movie ;
bprefix:isListedin bprefix:Documentaries .
Now I want to move the triples where title hasReleaseyear>2015 from this default graph to a named graph http://example.org/mynamedgraph.
I can construct the triples that I want to move using
CONSTRUCT {?title ?predicate ?object} WHERE{
?title ?predicate ?object.
?title bprefix:hasReleaseyear ?year FILTER(?year>2015)
}
What I could look online was that MOVE operation will move "all" the triples from default to this named graph. How can I filter the triples before moving them from default graph to named graph.

matching subsequent space separated numbers as different tokens

In a flat file,for which i'm trying to write a parser, there is a line like this:
//TN PN RO
0 5 3
TN,PN and RO are the parameter names (i have added here the line starting with "//" for better understanding. The actual file does not have it).
The ranges for each of these parameters are different.
TN can be 0 or 1, PN 0-7 and RO 0-3.
I understand why the following grammar does not work (0 and 1 matched by all lexer rules, 2 and 3 are matched by the PN and RO rules) but is there a way to achieve what i'm trying to do here.
grammar PARAM;
parameters: TN PN RO;
TN: [0-1];
RN: [0-7];
RO: [0-3];
WS : [ \r\t\n]+ -> skip ;
I like to match these overlapping numbers as different tokens. Otherwise i have to change my grammar to this and then in the the Java side check the ranges manually.
grammar PARAM;
parameters: DIGIT DIGIT DIGIT;
DIGIT: [0-7];
WS : [ \r\t\n]+ -> skip ;
Thanks.
Since the lexer does not know the context / number position on line (unless hacked by some custom code), it does not know whether to match 0 as TN, RN or RO. The right place to make this distinction is the parser.
You could do this to avoid checking the ranges in Java (although I would personally check them in Java rather than do this):
parameters: tn_param rn_param ro_param;
tn_param: TN_DIGIT;
rn_param: TN_DIGIT | RO_DIGIT | RN_DIGIT;
ro_param: TN_DIGIT | RO_DIGIT;
TN_DIGIT: [0-1];
RO_DIGIT: [2-3];
RN_DIGIT: [4-7];

Composing Database.Esqueleto queries, conditional joins and counting

How can I compose Database.Esqueleto queries in a modular way such that after defining a "base" query and the corresponding result set, I can restrict the result set by adding additional inner joins and where expressions.
Also, how can I convert the base query that returns a list of entities (or field tuples) into a query that counts the result set since the base query is not executed as such, but a modified version of it with LIMIT and OFFSET.
The following incorrect Haskell code snippet adopted from the Yesod Book hopefully clarifies what I'm aiming at.
{-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies, OverloadedStrings #-}
{-# LANGUAGE GADTs, FlexibleContexts #-}
import qualified Database.Persist as P
import qualified Database.Persist.Sqlite as PS
import Database.Persist.TH
import Control.Monad.IO.Class (liftIO)
import Data.Conduit
import Control.Monad.Logger
import Database.Esqueleto
import Control.Applicative
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Person
name String
age Int Maybe
deriving Show
BlogPost
title String
authorId PersonId
deriving Show
Comment
comment String
blogPostId BlogPostId
|]
main :: IO ()
main = runStdoutLoggingT $ runResourceT $ PS.withSqliteConn ":memory:" $ PS.runSqlConn $ do
runMigration migrateAll
johnId <- P.insert $ Person "John Doe" $ Just 35
janeId <- P.insert $ Person "Jane Doe" Nothing
jackId <- P.insert $ Person "Jack Black" $ Just 45
jillId <- P.insert $ Person "Jill Black" Nothing
blogPostId <- P.insert $ BlogPost "My fr1st p0st" johnId
P.insert $ BlogPost "One more for good measure" johnId
P.insert $ BlogPost "Jane's" janeId
P.insert $ Comment "great!" blogPostId
let baseQuery = select $ from $ \(p `InnerJoin` b) -> do 
on (p ^. PersonId ==. b ^. BlogPostAuthorId)
where_ (p ^. PersonName `like` (val "J%"))
return (p,b)
-- Does not compile
let baseQueryLimited = (,) <$> baseQuery <*> (limit 2)
-- Does not compile
let countingQuery = (,) <$> baseQuery <*> (return countRows)
-- Results in invalid SQL
let commentsQuery = (,) <$> baseQuery
<*> (select $ from $ \(b `InnerJoin` c) -> do
on (b ^. BlogPostId ==. c ^. CommentBlogPostId)
return ())
somePosts <- baseQueryLimited
count <- countingQuery
withComments <- commentsQuery
liftIO $ print somePosts
liftIO $ print ((head count) :: Value Int)
liftIO $ print withComments
return ()
Looking at the documentation and the type of select:
select :: (...) => SqlQuery a -> SqlPersistT m [r]
It's clear that upon calling select, we leave the world of pure composable queries (SqlQuery a) and enter the world of side effects (SqlPersistT m [r]). So we simply need to compose before we select.
let baseQuery = from $ \(p `InnerJoin` b) -> do
on (p ^. PersonId ==. b ^. BlogPostAuthorId)
where_ (p ^. PersonName `like` (val "J%"))
return (p,b)
let baseQueryLimited = do r <- baseQuery; limit 2; return r
let countingQuery = do baseQuery; return countRows
somePosts <- select baseQueryLimited
count <- select countingQuery
This works for limiting and counting. I haven't figured out how to do it for joins yet, but it looks like it should be possible.
For LIMIT and COUNT, hammar's answer is entirely correct so I'll not delve into them. I'll just reiterate that once you use select you'll not be able to change the query in any way again.
For JOINs, currently you are not able to do a INNER JOIN with a query that was defined in a different from (nor (FULL|LEFT|RIGHT) OUTER JOINs). However, you can do implicit joins. For example, if you have defined:
baseQuery =
from $ \(p `InnerJoin` b) -> do
on (p ^. PersonId ==. b ^. BlogPostAuthorId)
where_ (p ^. PersonName `like` val "J%")
return (p, b)
Then you may just say:
commentsQuery =
from $ \c -> do
(p, b) <- baseQuery
where_ (b ^. BlogPostId ==. c ^. CommentBlogPostId)
return (p, b, c)
Esqueleto then will generate something along the lines of:
SELECT ...
FROM Comment, Person INNER JOIN BlogPost
ON Person.id = BlogPost.authorId
WHERE Person.name LIKE "J%"
AND BlogPost.id = Comment.blogPostId
Not pretty but gets the job done for INNER JOINs. If you need to do a OUTER JOIN then you'll have to refactor your code so that all the OUTER JOINs are in the same from (note that you can do an implicit join between OUTER JOINs just fine).

Semantic Similarity Result interpretation

I'm performing a semantic similarity using a tool here,
I'm getting the following results, but cannot properly interprete them:
apple#n#1,banana#n#1 0.04809463683080774
apple#n#1,banana#n#2 0.13293629283742603
apple#n#2,banana#n#1 0.0
apple#n#2,banana#n#2 0.0
here is the code:
URL url = new URL ( "file" , null , "dictionary/3.0/dict" );
IDictionary dict = new Dictionary ( url ) ;
dict.open () ;
// look up first sense of the word " dog "
IIndexWord idxWord = dict . getIndexWord ( "dog" , POS.NOUN ) ;
IWordID wordID = idxWord . getWordIDs () . get (0) ; // 1 st meaning
List <IWordID> wordIDs = idxWord.getWordIDs();
JWS ws= new JWS ("dictionary", "3.0");
TreeMap <String,Double> scores1 = ws.getJiangAndConrath().jcn("apple", "banana", "n");
for (String s:scores1.keySet())
System.out.println(s+"\t"+scores1.get(s));
From the NLTK Documentation:
The Jiang Conrath similarity returns a score denoting how similar two
word senses are, based on the Information Content (IC) of the Least
Common Subsumer (most specific ancestor node) and that of the two
input Synsets. The relationship is given by the equation 1 / (IC(s1) +
IC(s2) - 2 * IC(lcs)).
A result of 0 means that the two concepts are not related at all.
A result near 1 would mean a very close relationship.
can you put me code source written in JAVA responsible for the execution of LeacockAndChodorow algorithm because I do have some problems with Url variable?

Call a token of rule B from rule A

I would like to know if and how I can call a token of rule B from rule A, as in the example below:
//Rule A
description
:'Description' ':' primaryActor.actorName ...... //I tried this way, but it doesn't work.
;
//Rule B1
primaryActor
:actorName PA_TYPE
;
//Rule B2
secondaryActor
:actorName SA_TYPE
;
actorName
:ARTICLE SMALL_NOUN
;
/* ... */
So, 'primaryActor' and 'secondaryActor' both have an 'actorName'. If we write a test in the interpreter such as "Description: a Doctor...", 'Doctor should be assigned to 'primaryActor.actorName. Because 'actorName' is of the same type for both primary and secondary actors, I don't want to create an actorName for each one of them but being able to distinguish the actorName through its including rule.