How to do dependency parsing in R language? - machine-learning

I did POSTagging. But how to do dependency parsing? Can I get the code for it in R language ?

Probably you already figured out. if not, how I did dependency parsing in R:
library(cleanNLP)
library(udpipe)
s <- "I prefer the morning flight through Denver"
cnlp_init_udpipe()
doc <- cnlp_annotate(s, as_strings = TRUE)
cnlp_get_dependency(doc, get_token = FALSE)

Related

What am I doing wrong with my AI?

I've been programming an AI with Lua that you communicate with it in my own logical language. I stumbled across a problem and I can't seem to figure this out.
I'm trying to put y/n questions in. I pretty much said: mi=David la; (sets variable to David. la; is punctuation) la mi=David dor la; (Is 'mi' equal to 'David'?)
When I typed that into it, 'ROBO-DUDE' didn't say anything.
if v == "lol" then
local yes = true
for _,v in pairs(mode[2]) do
if v == false then
print(v)
yes = false
end
print(yes)
end
print(yes)
if yes == true then
things = things .. "jar; "
else
things = things .. "awa; "
end
end
This block of code is in a loop for the 'la' statement. 'dor' means to respond yes/no, the lexer changes it to 'lol'.
When I tested it, the code seemed to skip the dor/lol part of the loop. I went to check the lexer.
if v == "dor" then
sentence[#sentence+1] = "lol"
end
I have no clue what went wrong here. I would like somebody's help on this problem.
Nevermind. I found the problem. When I used a for loop, I used the variable 'v' for the main parser loop and the one that looped through another table/array. I believe changing the variable (any of them) will fix my issue.

Coding in third-party EDI interface

first time posting here so please bare with. I'm working on a project with a third-party software provider in which they have a built in EDI interface. They have installed some templates that parse the data that comes through in an .xml file and dumps all the data into the correct tables and columns in our database.
These templates were installed about 4 years ago, much before my time. And anyone at the time who was involved in the project has since moved on, with no documentation on what programming language this is or how everything works together. It's a pretty terrible interface, there is no way to debug, or see what the code is doing without sending the same dummy data over and over again, until I can figure out what it's doing.
tl;dr: I have some code that I'm working on and have no resources or documentation on what language it is or how it's working from start to finish. Can someone help me identify please? If I call the third party for help, they will charge my company $225/hour just to look at the code. They say it will take them 4 hours to look at it. Maybe a few more hours to fix it.
Example of code:
if (N702<>"" or N711 <> "" or N715<>"" or N722<>"") {
CLEAR("edi_stop_note");
edi_stop_note$comment_type <- "OC";
N711_desc<-qual_lookup("40",N711);
edi_stop_note$comments <-concat("Trlr: ",N702," Desc: ",N711_desc," Len: ",N715," Type: ",N722);
ADDNOTE("edi_stop","edi_stop_note") ;
};
Another example:
LineCnt <- "-1";
Stop_No <- "0";
Stop_Seq <- "0";
CLEAR("edi_order");
CLEAR("edi_stop");
edi_order$shipper_stop_id <-edi_stop$id;
edi_order$version <- edi_version;
edi_order$gs_date_time <- date_time(gs04_date, gs05_time);
edi_order$gs06_group_cntlno <- gs06_incntlno;
edi_order$st02_trxset_cntlno <- st02_cntlno;
edi_order$partner_id <- gs02_partner;
edi_order$reply_created <- "N";
edi_order$isa13_intr_cntlno <- isa13_intr_cntlno;
edi_order$direction <- "I";
edi_order$alt_partner_id <- alt_partner_id;
TIME <- cur_time("4");
DATE <- cur_date("6") ;
B204 <- "";

Stanford type dependency, can not extract "prepositional modfier"

I am trying to extract the prepositional modifier, like it is stated in the Dependency Manual:
I try to parse the sentence :
"I saw a cat with a telescope" , using the code:
List<CoreMap> sentences = stanfordDocument.get(SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
Tree tree = sentence.get(TreeAnnotation.class);
TreebankLanguagePack languagePack = new PennTreebankLanguagePack();
GrammaticalStructureFactory grammaticalStructureFactory = languagePack.grammaticalStructureFactory();
GrammaticalStructure structure = grammaticalStructureFactory.newGrammaticalStructure(tree);
Collection<TypedDependency> typedDependencies = structure.typedDependenciesCollapsed();
for (TypedDependency td : typedDependencies) {
System.out.println(td.reln());
}
}
As stated in the Manual I was expecting to get : prep(saw, with).
In the Collection of the TypedDependeny I get only
"nsubj; root; det; dobj; det; prep_with" as relation type, and not the "prep/prepc" as stated in the http://robotics.usc.edu/~gkoch/DependencyManual.pdf (page 8).
I have also tried to extract pcomp : Prepositional compelement (page 7 of the manual) and it doesnt find it.
Did somebody encountered the same problem? Am I doing anything wrong?
CoreNLP outputs "Collapsed dependencies preserving a tree structure" (section 4.4 of the manual) from my experience. I think it's the same thing here (e.g. prep_with is a collapsed dependency of prep(saw, with))

erlang convert complex binary structure to JSON

I have a binary <<"{\"resp_child\":\"0\"}\n">> (as you can see it includes JSON) and I would like to extract this 0 as binary <<0>> from this binary.
I am new to erlang, i was trying
string:join(binary_to_list(<<"{\"resp_child\":\"0\"}\n">>), "")
but i get the JSON string as a result.
"{\"resp_child\":\"0\"}\n"
Don't know what to do further to get <<0>>.
Thank you.
Why not to use one of the Erlang JSON parsing library?
jsx
jiffy
mochijson2
proplists:get_value(<<"resp_child">>, jsx:decode(<<"{\"resp_child\":\"0\"}\n">>)).
So if you need to replace <<"0">>, <<"1">>, ... <<"9">> to <<0>>, <<1>>, ... <<9>> you can write converting function for this
Yeah, this code worked for me.
Struct = mochijson2:decode(<<"{\"resp_child\":\"0\"}\n">>),
{struct, JsonData} = Struct,
Digits = proplists:get_value(<<"resp_child">>, JsonData).
Digits is <<0>>, that what i want.
You can read more about proplists at: http://www.erlang.org/doc/man/proplists.html.
Thanks :)

Print the target of an outlink

According to the DOORS Reference Manual, this code will print the source module identification of an inlink:
Object o = current
string srcModName
for srcModName in o<-"*" do print srcModName "\n"
This does work, however what I'm trying to do is print the target module identification of an outlink. I thought simply switching o<- to o-> would do the trick, but it doesn't. Does anyone know why, and how to fix this?
Not sure why that doesn't work but this does:
Object o = current
string tgtMod
Link l
for l in o -> "*" do
{
tgtMod = target(l)
print tgtMod "\n"
}
It doesn't work simply because there is no loop construct with that signature. All you have to work with is what's listed in the DXL Reference Manual.
EDIT: I forgot to mention though that Steve's answer is the way to do it if you just want the name of the target module.

Resources