What's the tags meaning of Stanford dependency parser(3.9.1)? - nltk

I used the Stanford dependency parser(3.9.1) to parse a sentence, and I got the result as the following.
[[(('investigating', 'VBG'), 'nmod', ('years', 'NNS')),
(('years', 'NNS'), 'case', ('In', 'IN')),
(('years', 'NNS'), 'det', ('the', 'DT')),
(('years', 'NNS'), 'amod', ('last', 'JJ')),
(('years', 'NNS'), 'nmod', ('century', 'NN')),
(('century', 'NN'), 'case', ('of', 'IN')),
(('century', 'NN'), 'det', ('the', 'DT')),
(('century', 'NN'), 'amod', ('nineteenth', 'JJ')),
(('investigating', 'VBG'), 'nsubj', ('Planck', 'NNP')),
(('investigating', 'VBG'), 'aux', ('was', 'VBD')),
(('investigating', 'VBG'), 'dobj', ('problem', 'NN')),
(('problem', 'NN'), 'det', ('the', 'DT')),
(('problem', 'NN'), 'nmod', ('radiation', 'NN')),
(('radiation', 'NN'), 'case', ('of', 'IN')),
(('radiation', 'NN'), 'amod', ('black-body', 'JJ')),
(('radiation', 'NN'), 'acl', ('posed', 'VBN')),
(('posed', 'VBN'), 'advmod', ('first', 'RB')),
(('posed', 'VBN'), 'nmod', ('Kirchhoff', 'NNP')),
(('Kirchhoff', 'NNP'), 'case', ('by', 'IN')),
(('Kirchhoff', 'NNP'), 'advmod', ('earlier', 'RBR')),
(('earlier', 'RBR'), 'nmod:npmod', ('years', 'NNS')),
(('years', 'NNS'), 'det', ('some', 'DT')),
(('years', 'NNS'), 'amod', ('forty', 'JJ'))]]
Some of the tags meaning such as 'nmod' and 'acl' are missing in the StanfordDependencyManual.The newest manual version I can find is 3.7.0. I also find some explanation at a Standard_list_of_dependency_relations
But it still missed some tags.
Hence, my question is where can I find the newest version of the explanation of these tags? Thanks!

For the last few versions, the Stanford parser has been generating Universal Dependencies rather than Stanford Dependencies. The new relation set can be found here, and are listed below (for version 1 -- version 2 seems to be a work-in-progress still?):
acl: clausal modifier of noun
acl:relcl: relative clause modifier
advcl: adverbial clause modifier
advmod: adverbial modifier
amod: adjectival modifier
appos: appositional modifier
aux: auxiliary
auxpass: passive auxiliary
case: case marking
cc: coordination
cc:preconj: preconjunct
ccomp: clausal complement
compound: compound
compound:prt: phrasal verb particle
conj: conjunct
cop: copula
csubj: clausal subject
csubjpass: clausal passive subject
dep: dependent
det: determiner
det:predet: predeterminer
discourse: discourse element
dislocated: dislocated elements
dobj: direct object
expl: expletive
foreign: foreign words
goeswith: goes with
iobj: indirect object
list: list
mark: marker
mwe: multi-word expression
name: name
neg: negation modifier
nmod: nominal modifier
nmod:npmod: noun phrase as adverbial modifier
nmod:poss: possessive nominal modifier
nmod:tmod: temporal modifier
nsubj: nominal subject
nsubjpass: passive nominal subject
nummod: numeric modifier
parataxis: parataxis
punct: punctuation
remnant: remnant in ellipsis
reparandum: overridden disfluency
root: root
vocative: vocative
xcomp: open clausal complement
Although no longer maintained, you can get the old dependency format by setting the property depparse.language to English (see, e.g., here):
properties.setProperty("depparse.language", "English")

Related

Treesitter precedence not taking effect

I'm learning how to use tree sitter and making a grammar for parsing simple predicate logic. I'll clearly need precedence to make negation, ~, bind more tightly than conjunction and dis-junction, (/\ and \/). I think I've applied precedence correctly, practically copying the example in the documentation.
Here is the grammar:
module.exports = grammar({
name: 'Predicate_Calculus',
rules: {
// TODO: add the actual grammar rules
source_file: $ => repeat($._expression),
_expression: $ => choice($.identifier,
$._unary_expression,
$._binary_expression,
seq('(', $._expression, ')')),
_binary_expression: $ => choice(
$.and,
$.or
),
_unary_expression: $ => prec(2, choice(
$.not
)),
not: $ => seq('~', $._expression),
and: $ => prec.left(seq($._expression, "/\\", $._expression)),
or: $ => prec.left(seq($._expression, "\\/", $._expression)),
identifier: $ => /[a-z_]+/
}
});
However, when I run tree-sitter generate I get this error:
╰─➤ tree-sitter generate
Unresolved conflict for symbol sequence:
'~' _expression • '/\' …
Possible interpretations:
1: '~' (and _expression • '/\' _expression) (precedence: 0, associativity: Left)
2: (not '~' _expression) • '/\' …
Possible resolutions:
1: Specify a higher precedence in `and` than in the other rules.
2: Specify a higher precedence in `not` than in the other rules.
3: Specify a left or right associativity in `not`
4: Add a conflict for these rules: `not`, `and`
I believe what I've done with the prec(2 choice($.not)) is option 2 but it doesn't seem to be in effect in the grammar. I'm using tree-sitter 0.20.7 installed via cargo.
Okay, after experimenting with some more permutations I found that moving the precedence directive into the not definition fixes this issue.
_unary_expression: $ => choice(
$.not
),
not: $ => prec(2, seq('~', $._expression)),
Removing the precedence from _unary_expression and moving it to inside not.

Elixir - JasonHelpers - How can I send a keyword list to json_map?

I have a data structure that I want to convert to json and preserve the key order.
For example:
%{ x: 1, a: 5} should be converted to "{\"x\": 1, \"a\": 5}"
Poison does it without any problem. But when I upgrade to Jason, it changes to "{\"a\": 5, \"x\": 1}".
So I use JasonHelpers json_map to preserve the order like this:
Jason.Helpers.json_map([x: 1, a: 5])
It creates a fragment with correct order.
However, when I use a variable to do this:
list = [x: 1, a: 5]
Jason.Helpers.json_map(list)
I have an error:
** (Protocol.UndefinedError) protocol Enumerable not implemented for {:list, [line: 15], nil} of type Tuple.
....
QUESTION: How can I pass a pre-calculated list into Jason.Helpers.json_map ?
The calculation is complicated, so I don't want to repeat the code just to use json_map, but use the function that returns a list.
json_map/1 is a macro, from its docs:
Encodes a JSON map from a compile-time keyword.
It is designed for compiling JSON at compile-time, which is why it doesn't work with your runtime variable.
Support for encoding keyword lists was added to the Jason library a year ago, but it looks like it hasn't been pushed to hex yet. I managed to get it work by pulling the latest code from github:
defp deps do
[{:jason, git: "https://github.com/michalmuskala/jason.git"}]
end
Then by creating a struct that implements Jason.Encoder (adapted from this solution by the Jason author):
defmodule OrderedObject do
defstruct [:value]
def new(value), do: %__MODULE__{value: value}
defimpl Jason.Encoder do
def encode(%{value: value}, opts) do
Jason.Encode.keyword(value, opts)
end
end
end
Now we can encode objects with ordered keys:
iex(1)> Jason.encode!(OrderedObject.new([x: 1, a: 5]))
"{\"x\":1,\"a\":5}"
I don't know if this is part of the public API or just an implementation detail, but it appears you have some control of the order when implementing the Jason.Encoder protocol for a struct.
Let's say you've defined an Ordered struct:
defmodule Ordered do
#derive {Jason.Encoder, only: [:a, :x]}
defstruct [:a, :x]
end
If you encode the struct, the "a" key will be before the "x" key:
iex> Jason.encode!(%Ordered{a: 5, x: 1})
"{\"a\":5,\"x\":1}"
Let's reorder the keys we pass in to the :only option:
defmodule Ordered do
#derive {Jason.Encoder, only: [:x, :a]}
defstruct [:a, :x]
end
If we now encode the struct, the "x" key will be before the "a" key:
iex> Jason.encode!(%Ordered{a: 5, x: 1})
"{\"x\":1,\"a\":5}"

Business objects error while trying to use "OR" function

The formula is found below:
=NoFilter(Count([Same Day];All) Where ([Person Location- Facility (Curr)]="FH ORL") Where ([Order Catalog Short Description]="Physical Therapy For Whirlpool Wound Care Evaluation And Treatment") Or ([Person Location- Nurse Unit (Curr)] InList ("7TWR";"RIO1";"GT12";"GT14";"9TWR";"XTWR";"RIO")))
Error Message: The expression or sub-expression at position 10 in the 'Or' function uses an invalid data type
The structure of your formula is:
Nofilter (xxx) Where (yyy) Or (zzz InList(aaa))
It's complaining because it sees yyy as the only parameter to Where(). The structure should look like:
Nofilter (xxx) Where (yyy Or zzz InList(aaa))
So try:
=NoFilter(Count([Same Day];All) Where ([Person Location- Facility (Curr)]="FH ORL") Where ([Order Catalog Short Description]="Physical Therapy For Whirlpool Wound Care Evaluation And Treatment" Or [Person Location- Nurse Unit (Curr)] InList ("7TWR";"RIO1";"GT12";"GT14";"9TWR";"XTWR";"RIO")))

prolog function to infer new facts from data

I have a dataset containing "facts" recognizable to prolog, i.e.:
'be'('mr jiang', 'representative of china').
'support'('the establishment of the sar', 'mr jiang').
'be more than'('# distinguished guests', 'the principal representatives').
'end with'('the playing of the british national anthem', 'hong kong').
'follow at'('the stroke of midnight', 'this').
'take part in'('the ceremony', 'both countries').
'start at about'('# pm', 'the ceremony').
'end about'('# am', 'the ceremony').
I want the system to recognize that 'mr jiang' is referenced in both of the following "facts":
'be'('mr jiang', 'representative of china').
'support'('the establishment of the sar', 'mr jiang').
Subsequently the system should then infer:
'support'('the establishment of the sar', 'representative of china').
I've spent some time looking at the FOIL algorithm, do you think that would do the trick? But I guess that's overkill.
Would something like this work:
'X'('Y', 'Z') :-
'A'('Y', 'B') ∧ '0'('B', 'Z');
Is it possible to make such a general "rule" like that? Or does it have to be more specific?

Serializing recursive refs in Datomic

I have a user entity type in my Datomic database which can follow other user types. My issue comes when one user follows another user who is already following them:
User A follows user B and also User B follows user A
When I try to serialize (using Cheshire) I get a StackOverflowError because of (I'm guessing) infinite recursion on the :user/follows-users attribute.
How would I go about serializing (to json for an API) two Datomic entities that reference each another in such a way?
Here's a basic schema:
; schema
[{:db/id #db/id[:db.part/db]
:db/ident :user/username
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :user/follows-users
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db.install/_attribute :db.part/db}
; create users
{:db/id #db/id[:db.part/user -100000]
:user/username "Cheech"}
{:db/id #db/id[:db.part/user -200000]
:user/username "Chong"}
; create follow relationships
{:db/id #db/id[:db.part/user -100000]
:user/follows-users #db/id[:db.part/user -200000]}
{:db/id #db/id[:db.part/user -200000]
:user/follows-users #db/id[:db.part/user -100000]}]
And once the database is set up etc. on repl:
user=> (use '[cheshire.core :refer :all])
nil
user=> (generate-string (d/touch (d/entity (d/db conn) [:user/username "Cheech"])))
StackOverflowError clojure.lang.RestFn.invoke (RestFn.java:433)
The eager expansion of linked data structures is only safe in any language if they are cycle free. An api that promises to "eagerly expand data only until a cycle is found and then switch to linking (by user id)" may be harder to consume reliably than one that never expanded and always returned enough users to follow all the links in the response. For instance the request above could return the JSON:
[{"id": -100000,
"username": "Cheech",
"follows-users": [-200000]}
{"id": -200000,
"username": "Chong",
"follows-users": [-100000]}]
Where the list of selected users is found by reducing walk of the users graph into a set.
I'm a bit of a n00b to Datomic and am certain there must be a more idiomatic way of doing what #arthur-ulfeldt suggests above but in case anyone else is looking for a quick pointer on how to go about serializing Datomic EntityMaps into json where a self-referencing ref exists, here's the code that solves my problem:
(defn should-pack?
"Returns true if the attribute is type
ref with a cardinality of many"
[attr]
(->>
(d/q '[:find ?attr
:in $ ?attr
:where
[?attr :db/valueType ?type]
[?type :db/ident :db.type/ref]
[?attr :db/cardinality ?card]
[?card :db/ident :db.cardinality/many]]
(d/db CONN) attr)
first
empty?
not))
(defn make-serializable
"Stop infinite loops on recursive refs"
[entity]
(def ent (into {} entity))
(doseq [attr ent]
(if (should-pack? (first attr))
(def ent (assoc ent
(first attr)
(map #(get-entity-id %) (first (rest attr)))))))
ent)