Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
corpus2
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
corpus2
Commits
a0aee2cc
Commit
a0aee2cc
authored
13 years ago
by
ilor
Browse files
Options
Downloads
Patches
Plain Diff
add missing reader for the 'plain' format
parent
2380e8ea
Branches
Branches containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
libcorpus2/CMakeLists.txt
+1
-0
1 addition, 0 deletions
libcorpus2/CMakeLists.txt
libcorpus2/io/plainreader.cpp
+93
-0
93 additions, 0 deletions
libcorpus2/io/plainreader.cpp
libcorpus2/io/plainreader.h
+36
-0
36 additions, 0 deletions
libcorpus2/io/plainreader.h
with
130 additions
and
0 deletions
libcorpus2/CMakeLists.txt
+
1
−
0
View file @
a0aee2cc
...
...
@@ -63,6 +63,7 @@ SET(libcorpus2_STAT_SRC
io/nonewriter.cpp
io/orthwriter.cpp
io/pathwriter.cpp
io/plainreader.cpp
io/plainwriter.cpp
io/premorphwriter.cpp
io/reader.cpp
...
...
This diff is collapsed.
Click to expand it.
libcorpus2/io/plainreader.cpp
0 → 100644
+
93
−
0
View file @
a0aee2cc
#include
<libcorpus2/io/plainreader.h>
#include
<libpwrutils/foreach.h>
#include
<boost/algorithm/string.hpp>
#include
<boost/lexical_cast.hpp>
#include
<boost/make_shared.hpp>
#include
<fstream>
namespace
Corpus2
{
bool
PlainReader
::
registered
=
TokenReader
::
register_reader
<
PlainReader
>
(
"plain"
,
"ign,loose,strict"
);
PlainReader
::
PlainReader
(
const
Tagset
&
tagset
,
std
::
istream
&
is
)
:
BufferedSentenceReader
(
tagset
),
is_
(
&
is
)
{
}
PlainReader
::
PlainReader
(
const
Tagset
&
tagset
,
const
std
::
string
&
filename
)
:
BufferedSentenceReader
(
tagset
),
is_
()
{
is_owned_
.
reset
(
new
std
::
ifstream
(
filename
.
c_str
(),
std
::
ifstream
::
in
));
if
(
!
this
->
is_owned_
->
good
())
{
throw
Corpus2Error
(
"File not found!"
);
}
else
{
this
->
is_
=
is_owned_
.
get
();
}
}
Sentence
::
Ptr
PlainReader
::
actual_next_sentence
()
{
std
::
string
line
;
Sentence
::
Ptr
s
;
size_t
line_no
=
0
;
while
(
is
().
good
())
{
std
::
getline
(
is
(),
line
);
++
line_no
;
if
(
line
.
empty
())
{
return
s
;
}
else
{
std
::
vector
<
std
::
string
>
fields
;
boost
::
algorithm
::
split
(
fields
,
line
,
boost
::
is_any_of
(
"
\t
"
));
assert
(
!
fields
.
empty
());
if
(
fields
[
0
].
empty
())
{
//lexeme
if
(
s
->
empty
())
{
throw
Corpus2Error
(
"PlainReader lexemes without a token at "
+
boost
::
lexical_cast
<
std
::
string
>
(
line_no
));
}
if
(
fields
.
size
()
<
3
)
{
throw
Corpus2Error
(
"PlainReader not enough fields at "
+
boost
::
lexical_cast
<
std
::
string
>
(
line_no
));
}
const
std
::
string
&
lemma
=
fields
[
1
];
const
std
::
string
&
tag_string
=
fields
[
2
];
Tag
tag
=
parse_tag
(
tag_string
);
Token
*
last_token
=
s
->
tokens
().
back
();
last_token
->
add_lexeme
(
Lexeme
(
UnicodeString
::
fromUTF8
(
lemma
),
tag
));
if
(
fields
.
size
()
>
3
&&
fields
[
3
]
==
"disamb"
)
{
last_token
->
lexemes
().
back
().
set_disamb
(
true
);
}
}
else
{
// orth-ws
Token
*
t
=
new
Token
();
const
std
::
string
&
orth
=
fields
[
0
];
t
->
set_orth
(
UnicodeString
::
fromUTF8
(
orth
));
PwrNlp
::
Whitespace
::
Enum
wa
=
PwrNlp
::
Whitespace
::
Space
;
if
(
!
s
)
{
s
=
make_sentence
();
wa
=
PwrNlp
::
Whitespace
::
Newline
;
}
if
(
fields
.
size
()
>
1
)
{
wa
=
PwrNlp
::
Whitespace
::
from_string
(
fields
[
1
]);
}
t
->
set_wa
(
wa
);
s
->
append
(
t
);
}
}
}
return
s
;
}
void
PlainReader
::
set_option
(
const
std
::
string
&
option
)
{
BufferedSentenceReader
::
set_option
(
option
);
}
std
::
string
PlainReader
::
get_option
(
const
std
::
string
&
option
)
const
{
return
BufferedSentenceReader
::
get_option
(
option
);
}
}
/* end ns Corpus2 */
This diff is collapsed.
Click to expand it.
libcorpus2/io/plainreader.h
0 → 100644
+
36
−
0
View file @
a0aee2cc
#ifndef LIBSORPUS2_IO_PLAINREADER_H
#define LIBCORPUS2_IO_PLAINREADER_H
#include
<libcorpus2/io/reader.h>
#include
<boost/scoped_ptr.hpp>
namespace
Corpus2
{
class
PlainReader
:
public
BufferedSentenceReader
{
public:
PlainReader
(
const
Tagset
&
tagset
,
std
::
istream
&
is
);
PlainReader
(
const
Tagset
&
tagset
,
const
std
::
string
&
filename
);
std
::
istream
&
is
()
{
return
*
is_
;
}
void
set_option
(
const
std
::
string
&
option
);
std
::
string
get_option
(
const
std
::
string
&
option
)
const
;
static
bool
registered
;
protected
:
/// BufferedSentenceReader override
Sentence
::
Ptr
actual_next_sentence
();
std
::
istream
*
is_
;
boost
::
scoped_ptr
<
std
::
istream
>
is_owned_
;
};
}
/* end ns Corpus2 */
#endif // LIBCORPUS2_IO_PLAINREADER_H
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