8000 Merge pull request #77 from r0ller/wip · r0ller/alice@e9d4567 · GitHub
[go: up one dir, main page]

Skip to content

Commit e9d4567

Browse files
authored
Merge pull request #77 from r0ller/wip
fix functor lookup in hi_cvalue() to store constant, add desktop sh e…
2 parents b59f516 + d4fa889 commit e9d4567

File tree

5 files changed

+75
-14
lines changed

5 files changed

+75
-14
lines changed

hi.cpp

+25-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ int main(int argc,char **argv){
2424
"{\"lexeme\":\"BEENGV\",\"c_value\":\"\",\"word\":\"\",\"is_con\":false,\"is_qword\":false,\"mood\":\"indicative\"},"
2525
"{\"lexeme\":\"EXECUTABLEENGA\",\"c_value\":\"\",\"word\":\"\",\"is_con\":false,\"is_qword\":false,\"mood\":\"indicative\"}"
2626
"]}");*/
27+
/*analyses=hi_query("hi_desktop/hi.db","indicative","{\"dependencies\":[{\"source\":\"test\",\"timestamp\":1707253866,\"sentence\":\"what is executable ?\",\"rank\":0.333333,\"a_counter\":1,\"mood\":\"interrogative\",\"function\":\"BEENGV_1_6\",\"counter\":0,\"level\":0,\"word\":\"is\",\"lexeme\":\"\",\"d_key\":"
28+
"0,\"d_counter\":0,\"dependency\":\"BEENGV\",\"ref_d_key\":1,\"tags\":{\"is_root\":\"true\"},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1707253866,\"sentence\":\"what is executable ?\",\"rank\":0.333333,\"a_counter\":1,\"mood\":\"interrogative\","
29+
"\"function\":\"WHATENGPRON_1_1\",\"counter\":1,\"level\":1,\"word\":\"what\",\"lexeme\":\"BEENGV\",\"d_key\":1,\"d_counter\":1,\"dependency\":\"WHATENGPRON\",\"ref_d_key\":1,\"tags\":{\"is_qword\":\"true\"},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":"
30+
"1707253866,\"sentence\":\"what is executable ?\",\"rank\":0.333333,\"a_counter\":1,\"mood\":\"interrogative\",\"function\":\"PROPERTIES_1_6_1\",\"counter\":2,\"level\":1,\"word\":\"\",\"lexeme\":\"BEENGV\",\"d_key\":1,\"d_counter\":3,\"dependency\":"
31+
"\"PROPERTIES\",\"ref_d_key\":1,\"tags\":{},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1707253866,\"sentence\":\"what is executable ?\",\"rank\":0.333333,\"a_counter\":1,\"mood\":\"interrogative\",\"function\":\"FILEBEPROP_1_6_2\",\"counter\":"
32+
"3,\"level\":2,\"word\":\"\",\"lexeme\":\"PROPERTIES\",\"d_key\":1,\"d_counter\":4,\"dependency\":\"FILEBEPROP\",\"ref_d_key\":1,\"tags\":{},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1707253866,\"sentence\":\"what is executable ?\",\"rank\":0.333333,"
33+
"\"a_counter\":1,\"mood\":\"interrogative\",\"function\":\"EXECUTABLEENGA_1_8\",\"counter\":4,\"level\":3,\"word\":\"executable\",\"lexeme\":\"FILEBEPROP\",\"d_key\":1,\"d_counter\":2,\"dependency\":\"EXECUTABLEENGA\",\"ref_d_key\":1,\"tags\":{},\"c_value\":\"\"}]}");*/
2734
//Another example for 'when is peter's birthday ?'
2835
//"{\"dependencies\":[{\"source\":\"test\",\"timestamp\":1671634874,\"sentence\":\"when is peter's birthday ?\",\"rank\":1,\"a_counter\":1,\"mood\":\"interrogative\",\"function\":\"BEENGV_1_4\",\"counter\":0,\"level\":0,\"word\":\"is\",\"lexeme\":\"\",\"d_key\":0,\"d_counter\":0,\"dependency\":\"BEENGV\",\"ref_d_key\":1,\"tags\":{\"is_root\":\"true\"},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1671634874,\"sentence\":\"when is peter's birthday ?\",\"rank\":1,\"a_counter\":1,\"mood\":\"interrogative\",\"function\":\"WHENENGPRON_1\",\"counter\":1,\"level\":1,\"word\":\"when\",\"lexeme\":\"BEENGV\",\"d_key\":1,\"d_counter\":1,\"dependency\":\"WHENENGPRON\",\"ref_d_key\":1,\"tags\":{\"is_qword\":\"true\"},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1671634874,\"sentence\":\"when is peter's birthday ?\",\"rank\":1,\"a_counter\":1,\"mood\":\"interrogative\",\"function\":\"BIRTHDAYENGN_1_15\",\"counter\":2,\"level\":1,\"word\":\"birthday\",\"lexeme\":\"BEENGV\",\"d_key\":1,\"d_counter\":2,\"dependency\":\"BIRTHDAYENGN\",\"ref_d_key\":1,\"tags\":{\"qword\":\"when\"},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1671634874,\"sentence\":\"when is peter's birthday ?\",\"rank\":1,\"a_counter\":1,\"mood\":\"interrogative\",\"function\":\"CON_10\",\"counter\":3,\"level\":2,\"word\":\"peter's\",\"lexeme\":\"BIRTHDAYENGN\",\"d_key\":1,\"d_counter\":2,\"dependency\":\"CON\",\"ref_d_key\":1,\"tags\":{},\"c_value\":\"\"}]}";
2936
analyses=hi_query(argv[2],argv[3],argv[4]);
@@ -39,7 +46,10 @@ int main(int argc,char **argv){
3946
auto analysisObject=analysesArray[i].GetObject();
4047
//look for the first analysis having the qword tag and c_calue then stop
4148
string c_value=analysisObject["c_value"].GetString();
42-
if(analysisObject["tags"].HasMember("qword")==true&&c_value.empty()==false){
49+
//Making condition looser as hi_query() shall make sure that the relevant tags
50+
//appear in the analysis.
51+
//if(analysisObject["tags"].HasMember("qword")==true&&c_value.empty()==false){
52+
if(c_value.empty()==false){
4353
cout<<c_value<<endl;
4454
break;
4555
}
@@ -50,6 +60,20 @@ int main(int argc,char **argv){
5060
}
5161
else if(argc==6&&string(argv[1])=="-c"){
5262
//hi_state_cvalue("hi_desktop/hi.db","{\"source\":\"test\",\"timestamp\":1655803024,\"sentence\":\"file abc is executable .\",\"rank\":1,\"a_counter\":1,\"mood\":\"indicative\",\"function\":\"CON_6\"}","CON_6","test");
63+
/*hi_state_cvalue("hi_desktop/hi.db","{\"dependencies\":[{\"source\":\"test\",\"timestamp\":1707419402,\"sentence\":\"file def is executable .\",\"rank\":0.5,\"a_counter\":1,\"mood\":\"indicative\",\"function\":\"BEENGV_1_9\",\"counter\":0,\"level\":0,\"word\":\"is\",\"lexeme\":\"\",\"d_key\":"
64+
"0,\"d_counter\":0,\"dependency\":\"BEENGV\",\"ref_d_key\":1,\"tags\":{\"is_root\":\"true\"},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1707419402,\"sentence\":\"file def is executable .\",\"rank\":0.5,\"a_counter\":1,\"mood\":\"indicative\",\"f"
65+
"function\":\"PROPERTIES_1_9_1\",\"counter\":1,\"level\":1,\"word\":\"\",\"lexeme\":\"BEENGV\",\"d_key\":1,\"d_counter\":3,\"dependency\":\"PROPERTIES\",\"ref_d_key\":1,\"tags\":{},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1707419402,\"sentence\":"
66+
"\"file def is executable .\",\"rank\":0.5,\"a_counter\":1,\"mood\":\"indicative\",\"function\":\"FILEBEPROP_1_9_2\",\"counter\":2,\"level\":2,\"word\":\"\",\"lexeme\":\"PROPERTIES\",\"d_key\":1,\"d_counter\":4,\"dependency\":\"FILEBEPROP\",\"ref_d_key\":"
67+
"1,\"tags\":{},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1707419402,\"sentence\":\"file def is executable .\",\"rank\":0.5,\"a_counter\":1,\"mood\":\"indicative\",\"function\":\"EXECUTABLEENGA_1_12\",\"counter\":3,\"level\":3,\"word\":\"executable"
68+
"\",\"lexeme\":\"FILEBEPROP\",\"d_key\":1,\"d_counter\":2,\"dependency\":\"EXECUTABLEENGA\",\"ref_d_key\":1,\"tags\":{},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1707419402,\"sentence\":\"file def is executable .\",\"rank\":0.5,\"a_counter\":1,"
69+
"\"mood\":\"indicative\",\"function\":\"FILEENGN_1_1\",\"counter\":4,\"level\":3,\"word\":\"file\",\"lexeme\":\"FILEBEPROP\",\"d_key\":1,\"d_counter\":4,\"dependency\":\"FILEENGN\",\"ref_d_key\":1,\"tags\":{\"qword\":\"what\"},\"c_value\":\"\"},{\"source\""
70+
":\"test\",\"timestamp\":1707419402,\"sentence\":\"file def is executable .\",\"rank\":0.5,\"a_counter\":1,\"mood\":\"indicative\",\"function\":\"BEENGV_1_1_3\",\"counter\":5,\"level\":4,\"word\":\"\",\"lexeme\":\"FILEENGN\",\"d_key\":1,\"d_counter\":1,\""
71+
"dependency\":\"BEENGV\",\"ref_d_key\":1,\"tags\":{},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1707419402,\"sentence\":\"file def is executable .\",\"rank\":0.5,\"a_counter\":1,\"mood\":\"indicative\",\"function\":\"PROPERTIES_1_1_4\",\"counter\":"
72+
"6,\"level\":5,\"word\":\"\",\"lexeme\":\"BEENGV\",\"d_key\":1,\"d_counter\":3,\"dependency\":\"PROPERTIES\",\"ref_d_key\":1,\"tags\":{},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1707419402,\"sentence\":\"file def is executable .\",\"rank\":0.5"
73+
",\"a_counter\":1,\"mood\":\"indicative\",\"function\":\"FILEBEPROP_1_1_5\",\"counter\":7,\"level\":6,\"word\":\"\",\"lexeme\":\"PROPERTIES\",\"d_key\":1,\"d_counter\":4,\"dependency\":\"FILEBEPROP\",\"ref_d_key\":1,\"tags\":{},\"c_value\":\"\"},{\"source"
74+
"\":\"test\",\"timestamp\":1707419402,\"sentence\":\"file def is executable .\",\"rank\":0.5,\"a_counter\":1,\"mood\":\"indicative\",\"function\":\"FILEENGN_1_1_6\",\"counter\":8,\"level\":7,\"word\":\"\",\"lexeme\":\"FILEBEPROP\",\"d_key\":1,\"d_counter\""
75+
":4,\"dependency\":\"FILEENGN\",\"ref_d_key\":1,\"tags\":{},\"c_value\":\"\"},{\"source\":\"test\",\"timestamp\":1707419402,\"sentence\":\"file def is executable .\",\"rank\":0.5,\"a_counter\":1,\"mood\":\"indicative\",\"function\":\"CON_6\",\"counter\":9,"
76+
"\"level\":8,\"word\":\"def\",\"lexeme\":\"FILEENGN\",\"d_key\":1,\"d_counter\":2,\"dependency\":\"CON\",\"ref_d_key\":1,\"tags\":{},\"c_value\":\"\"}]}","FILEENGN_1_1_6","def");*/
5377
hi_state_cvalue(argv[2],argv[3],argv[4],argv[5]);
5478
}
5579
else{

hi_cvalue.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ int hi_state_cvalue(const char *db_uri,const char *deps,const char *function, co
1111
rapidjson::Value& dependencies=jsonDeps["dependencies"];
1212
if(dependencies.IsArray()==true&&dependencies.Size()>0){
1313
rapidjson::Value dependency;
14+
rapidjson::Value dependenciesArray=dependencies.GetArray();
1415
bool function_found=false;
15-
for(unsigned int i=0;i<dependencies.Size();++i){
16-
dependency=dependencies[i];
17-
if(dependency["function"].GetString()==std::string(function)){
18-
function_found=true;
19-
break;
16+
for(unsigned int i=0;i<dependenciesArray.Size();++i){
17+
dependency=dependenciesArray[i];
18+
if(dependency.HasMember("function")==true){
19+
if(dependency["function"].GetString()==std::string(function)){
20+
function_found=true;
21+
break;
22+
}
2023
}
2124
}
2225
if(function_found==true){
@@ -26,10 +29,11 @@ int hi_state_cvalue(const char *db_uri,const char *deps,const char *function, co
2629
+"' where source='"+dependency["source"].GetString()
2730
+"' and timestamp="+std::to_string(dependency["timestamp"].GetUint())
2831
+" and sentence='"+sqlite->escape(dependency["sentence"].GetString())
29-
+"' and rank="+std::to_string(dependency["rank"].GetUint())
32+
+"' and rank="+std::to_string(dependency["rank"].GetFloat())
3033
+" and a_counter="+std::to_string(dependency["a_counter"].GetUint())
3134
+" and mood='"+dependency["mood"].GetString()
3235
+"' and function='"+dependency["function"].GetString()+"';";
36+
//std::cout<<"sql:"<<sql_stmt<<std::endl;
3337
sqlite->exec_sql(sql_stmt);
3438
sqlite->close();
3539
}

hi_desktop/desktop_content.sql

+16-5
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,11 @@ insert into FUNCTORS values('WHATENGPRON', '1', 'WHATENGPRON_1');
308308

309309
insert into FUNCTOR_TAGS values('LISTENGV', '1', 'main_verb', '1', 'type', 'action');
310310
insert into FUNCTOR_TAGS values('LISTENGV', '1', 'imperative', '1', 'mood', 'imperative');
311+
insert into FUNCTOR_TAGS values('BEENGV', '1', 'main_verb', '1', 'is_root', 'true');
311312
insert into FUNCTOR_TAGS values('BEENGV', '1', 'interrogative', '1', 'mood', 'interrogative');
312313
insert into FUNCTOR_TAGS values('BEENGV', '1', 'indicative', '1', 'mood', 'indicative');
313-
insert into FUNCTOR_TAGS values('FILEENGN', '1', 'qw_what', '1', 'qword', 'what');
314+
insert into FUNCTOR_TAGS values('FILEENGN', '1', 'qword', '1', 'qword', 'what');
315+
insert into FUNCTOR_TAGS values('WHATENGPRON', '1', 'qword', '1', 'is_qword', 'true');
314316

315317
insert into RULE_TO_RULE_MAP values( 'ENG_Vbar1', 'ENG_V', 'ENG_NP', '1', '2', NULL, 'RCV', NULL, 'H', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'ENG');
316318
insert into RULE_TO_RULE_MAP values( 'ENG_Vbar1', 'ENG_V', 'ENG_NP', '2', '3', '4', 'N', NULL, 'N', NULL, NULL, 'CON', NULL, 'N', NULL, NULL, 'ENG');
@@ -376,6 +378,7 @@ insert into RULE_TO_RULE_MAP values( 'ENG_VP', 'ENG_Vbar5', 'ENG_AP', '1', NULL,
376378
/*begin rules for questions*/
377379
insert into RULE_TO_RULE_MAP values( 'ENG_VP', 'ENG_Vbar1', 'ENG_AP', '1', NULL, NULL, 'V', NULL, 'H', NULL, NULL, 'A', NULL, 'N', NULL, NULL, 'ENG');
378380
insert into RULE_TO_RULE_MAP values( 'ENG_Vbar6', 'ENG_V', 'ENG_AP', '1', NULL, NULL, 'V', NULL, 'H', NULL, NULL, 'A', NULL, 'N', NULL, NULL, 'ENG');
381+
insert into RULE_TO_RULE_MAP values( 'ENG_VP','ENG_Pron_qw','ENG_Vbar6', '1', NULL, NULL, 'V', NULL, 'N', NULL, NULL, 'Pron', NULL, 'H', NULL, NULL, 'ENG');
379382
/*end rules for questions*/
380383

381384
/*insert into RULE_TO_RULE_MAP values( 'HUN_VP', 'HUN_ImpVerbPfx', 'HUN_NP', '1', '2', NULL, 'Verb', NULL, 'H', NULL, 'Noun', NULL, 'N', NULL, 'HUN');
@@ -428,8 +431,9 @@ insert into DEPOLEX values('LISTENGV', '1', '1', NULL, NULL, NULL, '0', 'FILEENG
428431
insert into DEPOLEX values('LISTENGV', '2', '1', NULL, '1', NULL, '0', 'DIRECTORYENGN', '1');
429432
insert into DEPOLEX values('THATENGRPRO', '1', '1', NULL, NULL, NULL, '0', NULL, NULL);
430433

431-
insert into DEPOLEX values('BEENGV', '1', '1', '1', '2', '2', '0', 'NOTENGVNEG', '1');
432-
insert into DEPOLEX values('BEENGV', '1', '2', '1', '2', NULL, '0', 'PROPERTIES', '1');
434+
insert into DEPOLEX values('BEENGV', '1', '1', '1', '2', '2', '0', 'WHATENGPRON', '1');
435+
insert into DEPOLEX values('BEENGV', '1', '2', '1', '3', '3', '0', 'NOTENGVNEG', '1');
436+
insert into DEPOLEX values('BEENGV', '1', '3', '1', '3', NULL, '0', 'PROPERTIES', '1');
433437
insert into DEPOLEX values('BEENGV', '2', '1', '1', '2', '2', '0', 'NOTENGVNEG', '2');
434438
insert into DEPOLEX values('BEENGV', '2', '2', '1', '2', NULL, '0', 'PROPERTIES', '2');
435439
insert into DEPOLEX values('NOTENGVNEG', '1', '1', NULL, '1', NULL, '0', 'PROPERTIES', '1');
@@ -473,6 +477,8 @@ insert into DEPOLEX values('ANAENGDET', '1', '1', NULL, NULL, NULL, NULL, NULL,
473477
/*insert into DEPOLEX values('TOENGPREP', '1', '1', NULL, NULL, NULL, NULL, NULL, NULL);
474478
insert into DEPOLEX values('TOENGPAR', '1', '1', NULL, NULL, NULL, NULL, NULL, NULL);*/
475479

480+
insert into DEPOLEX values('WHATENGPRON', '1', '1', NULL, NULL, NULL, NULL, NULL, NULL);
481+
476482
/*insert into GRAMMAR values('ENG','S','ENG_VP',NULL,NULL,NULL);*/
477483
insert into GRAMMAR values('ENG','S','ENG_VP','ENG_Punct',NULL,
478484
'"const node_info& ENG_VP=sparser->get_node_info($1);
@@ -638,7 +644,7 @@ insert into GRAMMAR values('ENG','ENG_Vbar5','ENG_N_Sg','ENG_V',NULL,
638644
'"const node_info& ENG_N_Sg=sparser->get_node_info($1);
639645
const node_info& ENG_V=sparser->get_node_info($2);
640646
sparser->add_feature_to_leaf(ENG_V,"main_verb");
641-
sparser->add_feature_to_leaf(ENG_N_Sg,"N",std::string("qw_what"));
647+
sparser->add_feature_to_leaf(ENG_N_Sg,"N",std::string("qword"));
642648
logger::singleton()==NULL?(void)0:logger::singleton()->log(0,"ENG_Vbar5->ENG_N_Sg ENG_V");
643649
$$=sparser->combine_nodes("ENG_Vbar5",ENG_V,ENG_N_Sg);"');
644650
insert into GRAMMAR values('ENG','ENG_VP','ENG_Vbar5','ENG_DP',NULL,NULL);
@@ -662,7 +668,12 @@ insert into GRAMMAR values('ENG','ENG_Pron_3sg','t_ENG_Pron_3sg',NULL,NULL,NULL)
662668
insert into GRAMMAR values('ENG','ENG_Pron_wh','t_ENG_Pron_wh',NULL,NULL,NULL);
663669
insert into GRAMMAR values('ENG','ENG_Pron','ENG_Pron_Stem','ENG_Pron_3sg',NULL,NULL);
664670
insert into GRAMMAR values('ENG','ENG_Pron_qw','ENG_Pron','ENG_Pron_wh',NULL,NULL);
665-
insert into GRAMMAR values('ENG','ENG_VP','ENG_Pron_qw','ENG_Vbar6',NULL,NULL);
671+
insert into GRAMMAR values('ENG','ENG_VP','ENG_Pron_qw','ENG_Vbar6',NULL,
672+
'"const node_info& ENG_Pron_qw=sparser->get_node_info($1);
673+
const node_info& ENG_Vbar6=sparser->get_node_info($2);
674+
sparser->add_feature_to_leaf(ENG_Pron_qw,"Pron",std::string("qword"));
675+
logger::singleton()==NULL?(void)0:logger::singleton()->log(0,"ENG_VP->ENG_Pron_qw ENG_Vbar6");
676+
$$=sparser->combine_nodes("ENG_VP",ENG_Pron_qw,ENG_Vbar6);"');
666677
insert into GRAMMAR values('ENG','ENG_Vbar6','ENG_V','ENG_AP',NULL,
667678
'"const node_info& ENG_V=sparser->get_node_info($1);
668679
const node_info& ENG_AP=sparser->get_node_info($2);

hi_desktop/functors/beengv_1.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ eval "$1"_out='"$out"';
4848
elif [ $mood = "interrogative" -a -n "$morph" ]; then
4949
echo $mood;
5050
echo $morph;
51-
analyses="$(/home/r0ller/hi/build/hi -q /home/r0ller/hi/build/hi_desktop/hi.db BEENGV 1 {})";
52-
echo $analyses;
51+
script --quiet -c "/home/llencses/projects/hi_netbsd/hi/build/hi -q /home/llencses/projects/hi_netbsd/hi/build/hi_desktop/hi.db indicative \"$analysis_deps\"" /dev/null;
5352
elif [ $mood = "indicative" ]; then
5453
echo $mood;
5554
fi;

hi_desktop/functors/fileengn_1.sh

+23
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,27 @@ elif [ $mood = "interrogative" ]; then
4444
echo $mood;
4545
elif [ $mood = "indicative" ]; then
4646
echo $mood;
47+
c=1;
48+
for i in $2;
49+
do
50+
p=$(($c+2));
51+
eval v="\$$p";
52+
echo name;
53+
echo $i;
54+
echo content;
55+
echo "$v";
56+
case "$i" in
57+
*_out) if [ -n "$(echo "$v"|grep '"gcat":"CON"')" ];
58+
then out="$out""$(echo "$v"|cut -f3 -d:|cut -f1 -d,|tr -d \")";
59+
else out="$v";
60+
fi;
61+
;;
62+
esac;
63+
c=$(($c+1));
64+
done;
65+
echo "Inserting c_value:"$out;
66+
unescaped_analysis=$(echo "$analysis_deps"|tr -d \\\\);
67+
echo "$unescaped_analysis";
68+
echo $1;
69+
/home/llencses/projects/hi_netbsd/hi/build/hi -c /home/llencses/projects/hi_netbsd/hi/build/hi_desktop/hi.db "$unescaped_analysis" $1 $out;
4770
fi;

0 commit comments

Comments
 (0)
0