Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WCCL
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Analysers
WCCL
Commits
94aca274
Commit
94aca274
authored
14 years ago
by
ilor
Browse files
Options
Downloads
Patches
Plain Diff
sentence loading in wcclparser
parent
fa0d5168
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wcclparser/main.cpp
+40
-27
40 additions, 27 deletions
wcclparser/main.cpp
with
40 additions
and
27 deletions
wcclparser/main.cpp
+
40
−
27
View file @
94aca274
#include
<cstdlib>
#include
<fstream>
#include
<libwccl/values/strset.h>
#include
<libwccl/parser/Parser.h>
...
...
@@ -6,6 +7,7 @@
#include
<boost/bind.hpp>
#include
<boost/program_options.hpp>
#include
<libcorpus2/io/xcesreader.h>
#include
<antlr/MismatchedTokenException.hpp>
// ----------------------------------------------------------------------------
...
...
@@ -86,7 +88,7 @@ void libedit_read_loop(boost::function<bool (const std::string&)>& line_cb)
}
#endif
bool
process_line
(
const
std
::
string
&
line
,
Parser
&
parser
)
bool
process_line
(
const
std
::
string
&
line
,
Parser
&
parser
,
Wccl
::
SentenceContext
&
sc
)
{
if
(
line
.
empty
()
||
line
==
"exit"
||
line
==
"quit"
)
{
return
true
;
...
...
@@ -97,10 +99,6 @@ bool process_line(const std::string& line, Parser& parser)
boost
::
shared_ptr
<
const
Wccl
::
Value
>
retVal
;
boost
::
shared_ptr
<
ANTLRParserResultBase
>
retOp
;
boost
::
shared_ptr
<
Corpus2
::
Sentence
>
sentence
;
sentence
.
reset
(
new
Corpus2
::
Sentence
);
Wccl
::
SentenceContext
sc
(
sentence
);
try
{
retOp
=
parser
.
parseAnyOperator
(
line
);
if
(
retOp
)
{
...
...
@@ -138,6 +136,8 @@ int main(int argc, char** argv)
{
std
::
string
tagset_load
=
"kipi"
;
std
::
string
query
=
""
;
std
::
string
sentence_load
=
""
;
std
::
string
position
=
"0"
;
bool
quiet
=
false
;
using
boost
::
program_options
::
value
;
...
...
@@ -145,6 +145,10 @@ int main(int argc, char** argv)
desc
.
add_options
()
(
"tagset,t"
,
value
(
&
tagset_load
),
"Tagset to use
\n
"
)
(
"sentence,s"
,
value
(
&
sentence_load
),
"Sentence to load (XCES)
\n
"
)
(
"position,p"
,
value
(
&
position
),
"Position in the sentence to use, 'all' iterates through the sentence
\n
"
)
(
"query,Q"
,
value
(
&
query
),
"Query to run (disables interactive mode)
\n
"
)
(
"quiet,q"
,
value
(
&
quiet
)
->
zero_tokens
(),
...
...
@@ -171,31 +175,40 @@ int main(int argc, char** argv)
}
try
{
Corpus2
::
get_named_tagset
(
tagset_load
);
}
catch
(
Corpus2
::
FileNotFound
&
e
)
{
std
::
cerr
<<
e
.
info
()
<<
std
::
endl
;
return
2
;
}
const
Corpus2
::
Tagset
&
tagset
=
Corpus2
::
get_named_tagset
(
tagset_load
);
Parser
parser
(
tagset
);
if
(
!
query
.
empty
())
{
process_line
(
query
,
parser
);
return
0
;
}
if
(
clear_screen
())
{
//
}
boost
::
function
<
bool
(
const
std
::
string
&
)
>
f
;
f
=
boost
::
bind
(
&
process_line
,
_1
,
boost
::
ref
(
parser
));
const
Corpus2
::
Tagset
&
tagset
=
Corpus2
::
get_named_tagset
(
tagset_load
);
boost
::
shared_ptr
<
Corpus2
::
Sentence
>
sentence
;
if
(
sentence_load
.
empty
())
{
sentence
.
reset
(
new
Corpus2
::
Sentence
);
}
else
{
std
::
ifstream
ifs
(
sentence_load
.
c_str
());
if
(
ifs
.
good
())
{
Corpus2
::
XcesReader
reader
(
tagset
,
ifs
,
false
);
sentence
.
reset
(
reader
.
get_next_sentence
());
std
::
cerr
<<
"Sentence loaded, "
<<
sentence
->
size
()
<<
" tokens.
\n
"
;
}
else
{
throw
Wccl
::
FileNotFound
(
sentence_load
,
""
,
"Sentence"
);
}
}
Wccl
::
SentenceContext
sc
(
sentence
);
int
pos
=
atoi
(
position
.
c_str
());
sc
.
set_position
(
pos
);
Parser
parser
(
tagset
);
if
(
!
query
.
empty
())
{
process_line
(
query
,
parser
,
sc
);
return
0
;
}
boost
::
function
<
bool
(
const
std
::
string
&
)
>
f
;
f
=
boost
::
bind
(
&
process_line
,
_1
,
boost
::
ref
(
parser
),
boost
::
ref
(
sc
));
#ifdef HAVE_LIBEDIT
libedit_read_loop
(
f
);
libedit_read_loop
(
f
);
#else
std_read_loop
(
f
);
std_read_loop
(
f
);
#endif
}
catch
(
PwrNlp
::
PwrNlpError
&
e
)
{
std
::
cerr
<<
e
.
info
()
<<
std
::
endl
;
return
2
;
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
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