Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
old_macaon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Franck Dary
old_macaon
Commits
d3babc3d
Commit
d3babc3d
authored
6 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Added a parser gold
parent
41db42dc
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
trainer/src/macaon_train.cpp
+1
-2
1 addition, 2 deletions
trainer/src/macaon_train.cpp
transition_machine/src/Oracle.cpp
+157
-0
157 additions, 0 deletions
transition_machine/src/Oracle.cpp
with
158 additions
and
2 deletions
trainer/src/macaon_train.cpp
+
1
−
2
View file @
d3babc3d
...
...
@@ -266,12 +266,11 @@ int main(int argc, char * argv[])
}
else
{
createTemplatePath
();
updatePaths
();
ProgramParameters
::
newTemplatePath
=
ProgramParameters
::
templatePath
;
createExpPath
();
Dict
::
deleteDicts
();
launchTraining
();
removeTemplatePath
();
}
return
0
;
...
...
This diff is collapsed.
Click to expand it.
transition_machine/src/Oracle.cpp
+
157
−
0
View file @
d3babc3d
#include
"Oracle.hpp"
#include
"util.hpp"
#include
"File.hpp"
#include
"Action.hpp"
std
::
map
<
std
::
string
,
std
::
unique_ptr
<
Oracle
>
>
Oracle
::
str2oracle
;
...
...
@@ -232,6 +233,162 @@ void Oracle::createDatabase()
return
action
==
std
::
string
(
"RULE LEMMA ON FORM "
)
+
rule
||
c
.
head
>=
(
int
)
c
.
tapes
[
0
].
ref
.
size
()
-
1
;
})));
str2oracle
.
emplace
(
"parser_gold"
,
std
::
unique_ptr
<
Oracle
>
(
new
Oracle
(
[](
Oracle
*
oracle
)
{
File
file
(
oracle
->
filename
,
"r"
);
FILE
*
fd
=
file
.
getDescriptor
();
char
b1
[
1024
];
if
(
fscanf
(
fd
,
"Default : %[^
\n
]
\n
"
,
b1
)
==
1
)
oracle
->
data
[
b1
]
=
"ok"
;
while
(
fscanf
(
fd
,
"%[^
\n
]
\n
"
,
b1
)
==
1
)
oracle
->
data
[
b1
]
=
"ok"
;
},
[](
Config
&
c
,
Oracle
*
oracle
)
{
for
(
auto
&
it
:
oracle
->
data
)
{
Action
action
(
it
.
first
);
if
(
!
action
.
appliable
(
c
))
continue
;
if
(
oracle
->
actionIsZeroCost
(
c
,
it
.
first
))
return
it
.
first
;
}
fprintf
(
stderr
,
"ERROR (%s) : No zero cost action found by the oracle. Aborting.
\n
"
,
ERRINFO
);
exit
(
1
);
return
std
::
string
(
""
);
},
[](
Config
&
c
,
Oracle
*
,
const
std
::
string
&
action
)
{
auto
&
labels
=
c
.
getTape
(
"LABEL"
);
auto
&
govs
=
c
.
getTape
(
"GOV"
);
auto
&
eos
=
c
.
getTape
(
"EOS"
);
int
head
=
c
.
head
;
int
stackHead
=
c
.
stackEmpty
()
?
0
:
c
.
stackTop
();
int
stackGov
=
stackHead
+
std
::
stoi
(
govs
.
ref
[
stackHead
]);
int
headGov
=
head
+
std
::
stoi
(
govs
.
ref
[
head
]);
int
sentenceStart
=
c
.
head
-
1
<
0
?
0
:
c
.
head
-
1
;
int
sentenceEnd
=
c
.
head
;
while
(
sentenceStart
>=
0
&&
eos
.
ref
[
sentenceStart
]
!=
"1"
)
sentenceStart
--
;
if
(
sentenceStart
!=
0
)
sentenceStart
++
;
while
(
sentenceEnd
<
(
int
)
eos
.
ref
.
size
()
&&
eos
.
ref
[
sentenceEnd
]
!=
"1"
)
sentenceEnd
++
;
if
(
sentenceEnd
==
(
int
)
eos
.
ref
.
size
())
sentenceEnd
--
;
auto
parts
=
split
(
action
);
if
(
parts
[
0
]
==
"SHIFT"
)
{
for
(
int
i
=
sentenceStart
;
i
<=
sentenceEnd
;
i
++
)
{
if
(
!
isNum
(
govs
.
ref
[
i
]))
{
fprintf
(
stderr
,
"ERROR (%s) : govs.ref[%d] = <%s>. Aborting.
\n
"
,
ERRINFO
,
i
,
govs
.
ref
[
i
].
c_str
());
exit
(
1
);
}
int
otherGov
=
i
+
std
::
stoi
(
govs
.
ref
[
i
]);
for
(
int
j
=
0
;
j
<
c
.
stackSize
();
j
++
)
{
auto
s
=
c
.
stackGetElem
(
j
);
if
(
s
==
i
)
if
(
otherGov
==
head
||
headGov
==
s
)
return
false
;
}
}
return
eos
.
ref
[
stackHead
]
!=
"1"
;
}
else
if
(
parts
[
0
]
==
"WRITE"
&&
parts
.
size
()
==
4
)
{
auto
object
=
split
(
parts
[
1
],
'.'
);
if
(
object
[
0
]
==
"b"
)
{
if
(
parts
[
2
]
==
"LABEL"
)
return
action
==
"WRITE b.0 LABEL "
+
c
.
getTape
(
"LABEL"
).
ref
[
c
.
head
]
||
c
.
head
>=
(
int
)
c
.
tapes
[
0
].
ref
.
size
()
-
1
||
c
.
getTape
(
"LABEL"
).
ref
[
c
.
head
]
==
"root"
;
else
if
(
parts
[
2
]
==
"GOV"
)
return
action
==
"WRITE b.0 GOV "
+
c
.
getTape
(
"GOV"
).
ref
[
c
.
head
]
||
c
.
head
>=
(
int
)
c
.
tapes
[
0
].
ref
.
size
()
-
1
;
}
else
if
(
object
[
0
]
==
"s"
)
{
int
index
=
c
.
stackGetElem
(
-
1
);
if
(
parts
[
2
]
==
"LABEL"
)
return
action
==
"WRITE s.-1 LABEL "
+
c
.
getTape
(
"LABEL"
).
ref
[
index
]
||
c
.
getTape
(
"LABEL"
).
ref
[
index
]
==
"root"
;
else
if
(
parts
[
2
]
==
"GOV"
)
return
action
==
"WRITE s.-1 GOV "
+
c
.
getTape
(
"GOV"
).
ref
[
index
];
}
return
false
;
}
else
if
(
parts
[
0
]
==
"REDUCE"
)
{
for
(
int
i
=
head
;
i
<=
sentenceEnd
;
i
++
)
{
int
otherGov
=
i
+
std
::
stoi
(
govs
.
ref
[
i
]);
if
(
otherGov
==
stackHead
)
return
false
;
}
return
eos
.
ref
[
stackHead
]
!=
"1"
;
}
else
if
(
parts
[
0
]
==
"LEFT"
)
{
if
(
eos
.
ref
[
stackHead
]
==
"1"
)
return
false
;
if
(
parts
.
size
()
==
2
&&
stackGov
==
head
&&
labels
.
ref
[
stackHead
]
==
parts
[
1
])
return
true
;
if
(
parts
.
size
()
==
1
&&
stackGov
==
head
)
return
true
;
for
(
int
i
=
head
;
i
<=
sentenceEnd
;
i
++
)
{
int
otherGov
=
i
+
std
::
stoi
(
govs
.
ref
[
i
]);
if
(
otherGov
==
stackHead
||
stackGov
==
i
)
return
false
;
}
return
parts
.
size
()
==
1
||
labels
.
ref
[
stackHead
]
==
parts
[
1
];
}
else
if
(
parts
[
0
]
==
"RIGHT"
)
{
for
(
int
j
=
0
;
j
<
c
.
stackSize
();
j
++
)
{
auto
s
=
c
.
stackGetElem
(
j
);
if
(
s
==
c
.
stackTop
())
continue
;
int
otherGov
=
s
+
std
::
stoi
(
govs
.
ref
[
s
]);
if
(
otherGov
==
head
||
headGov
==
s
)
return
false
;
}
for
(
int
i
=
head
;
i
<=
sentenceEnd
;
i
++
)
if
(
headGov
==
i
)
return
false
;
return
parts
.
size
()
==
1
||
labels
.
ref
[
head
]
==
parts
[
1
];
}
else
if
(
parts
[
0
]
==
"EOS"
)
{
return
eos
.
ref
[
stackHead
]
==
"1"
;
}
return
false
;
})));
str2oracle
.
emplace
(
"parser"
,
std
::
unique_ptr
<
Oracle
>
(
new
Oracle
(
[](
Oracle
*
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment