Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WCCL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Analysers
WCCL
Commits
380efc1e
Commit
380efc1e
authored
Apr 29, 2011
by
Adam Wardynski
Browse files
Options
Downloads
Patches
Plain Diff
Class to hold lexicon data.
parent
006c4af2
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
libwccl/CMakeLists.txt
+1
-0
1 addition, 0 deletions
libwccl/CMakeLists.txt
libwccl/lexicon/lexicon.cpp
+46
-0
46 additions, 0 deletions
libwccl/lexicon/lexicon.cpp
libwccl/lexicon/lexicon.h
+62
-0
62 additions, 0 deletions
libwccl/lexicon/lexicon.h
with
109 additions
and
0 deletions
libwccl/CMakeLists.txt
+
1
−
0
View file @
380efc1e
...
@@ -27,6 +27,7 @@ endif(WIN32)
...
@@ -27,6 +27,7 @@ endif(WIN32)
SET
(
libwccl_STAT_SRC
SET
(
libwccl_STAT_SRC
exception.cpp
exception.cpp
lexicon/lexicon.cpp
ops/formatters.cpp
ops/formatters.cpp
ops/functions/bool/iteration.cpp
ops/functions/bool/iteration.cpp
ops/functions/bool/iterations/atleast.cpp
ops/functions/bool/iterations/atleast.cpp
...
...
This diff is collapsed.
Click to expand it.
libwccl/lexicon/lexicon.cpp
0 → 100644
+
46
−
0
View file @
380efc1e
#include
<libwccl/lexicon/lexicon.h>
#include
<libpwrutils/util.h>
#include
<libwccl/exception.h>
#include
<libpwrutils/foreach.h>
#include
<boost/make_shared.hpp>
namespace
Wccl
{
const
UnicodeString
&
Lexicon
::
translate
(
const
icu_44
::
UnicodeString
&
key
)
const
{
static
UnicodeString
empty
;
map_t
::
const_iterator
i
=
map_
.
find
(
key
);
if
(
i
==
map_
.
end
())
{
return
empty
;
}
return
i
->
second
;
}
boost
::
shared_ptr
<
StrSet
>
Lexicon
::
translate
(
const
StrSet
&
set
)
const
{
boost
::
shared_ptr
<
StrSet
>
ret_set
=
boost
::
make_shared
<
StrSet
>
();
foreach
(
const
UnicodeString
&
s
,
set
.
get_value
())
{
const
UnicodeString
&
v
=
translate
(
s
);
if
(
!
v
.
isEmpty
())
{
ret_set
->
insert
(
v
);
}
}
return
ret_set
;
}
void
Lexicon
::
insert
(
const
UnicodeString
&
key
,
const
UnicodeString
&
value
)
{
if
(
has_key
(
key
))
{
throw
InvalidArgument
(
"key"
,
PwrNlp
::
to_utf8
(
key
)
+
" - entry already added."
);
}
if
(
key
.
isEmpty
())
{
throw
InvalidArgument
(
"key"
,
"Cannot add an empty string."
);
}
if
(
value
.
isEmpty
())
{
throw
InvalidArgument
(
"value"
,
"Cannot add an empty string."
);
}
map_
[
key
]
=
value
;
}
}
/* end ns Wccl */
This diff is collapsed.
Click to expand it.
libwccl/lexicon/lexicon.h
0 → 100644
+
62
−
0
View file @
380efc1e
#ifndef LIBWCCL_LEXICON_LEXICON_H
#define LIBWCCL_LEXICON_LEXICON_H
#include
<boost/unordered_map.hpp>
#include
<boost/noncopyable.hpp>
#include
<libcorpus2/lexeme.h>
// for unicodestring hash
#include
<libwccl/values/strset.h>
namespace
Wccl
{
class
Lexicon
:
boost
::
noncopyable
{
public:
typedef
boost
::
unordered_map
<
UnicodeString
,
UnicodeString
>
map_t
;
Lexicon
(
const
std
::
string
&
name
)
:
name_
(
name
)
{
BOOST_ASSERT
(
!
name_
.
empty
());
}
/**
* Translate given key to a value held in this lexicon.
* @returns Value assigned to the given key, if present.
* Empty UnicodeString if the key was not present.
*/
const
UnicodeString
&
translate
(
const
UnicodeString
&
key
)
const
;
/**
* Translate given set of strings to corresponding values
* from the lexicon.
* Nonexisting keys will translate to nothing (will be removed
* from output).
*/
boost
::
shared_ptr
<
StrSet
>
translate
(
const
StrSet
&
set
)
const
;
std
::
string
name
()
const
{
return
name_
;
}
bool
has_key
(
const
UnicodeString
&
key
)
const
{
return
map_
.
find
(
key
)
!=
map_
.
end
();
}
void
insert
(
const
UnicodeString
&
key
,
const
UnicodeString
&
value
);
void
insert
(
const
UnicodeString
&
key
)
{
insert
(
key
,
key
);
}
const
map_t
&
map
()
const
{
return
map_
;
}
private
:
map_t
map_
;
const
std
::
string
name_
;
};
}
/* end ns Wccl */
#endif // LIBWCCL_LEXICON_LEXICON_H
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