Skip to content
Snippets Groups Projects
Commit 712d1481 authored by Adam Radziszewski's avatar Adam Radziszewski
Browse files

starter of convenience functions for tagging

parent dceb65a4
Branches
No related merge requests found
......@@ -50,6 +50,7 @@ SET(libcorpus2_STAT_SRC
lexeme.cpp
sentence.cpp
tag.cpp
tagging.cpp
tagset.cpp
tagsetmanager.cpp
tagsetparser.cpp
......
/*
Copyright (C) 2010 Tomasz Śniatowski, Adam Radziszewski
Part of the libcorpus2 project
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the LICENSE and COPYING files for more details.
*/
#include <libcorpus2/tagging.h>
#include <libcorpus2/tagsetmanager.h>
// #include <libpwrutils/foreach.h>
namespace Corpus2 {
Tag get_attribute_mask(const Tagset& tagset, std::string attr_name)
{
if(attr_name.empty())
{
// return all-POS mask
Tag t;
for (idx_t pos_idx = 0; pos_idx < tagset.pos_count(); ++pos_idx) {
t.add_pos(tagset.get_pos_mask(pos_idx));
}
return t;
}
else
{
return Tag(0, tagset.get_attribute_mask(attr_name));
}
}
} /* end ns Corpus2 */
/*
Copyright (C) 2010 Tomasz Śniatowski, Adam Radziszewski
Part of the libcorpus2 project
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the LICENSE and COPYING files for more details.
*/
#ifndef LIBCORPUS2_TAGGING_H
#define LIBCORPUS2_TAGGING_H
#include <libcorpus2/tag.h>
#include <libcorpus2/tagset.h>
namespace Corpus2 {
/**
* Creates a mask having all values of the given attribute set.
* Pass an empty string to get a mask for all POS values.
* The resulting object should only be used for masking as it won't be
* a valid tag.
*
* @arg tagset_name tagset to use
* @arg attr_name attrinbute as defined in tagset or empty string for POS
* @return mask for given attribute
*/
Tag get_attribute_mask(const Tagset& tagset,
const std::string attr_name);
} /* end ns Corpus2 */
#endif // LIBCORPUS2_TAGGING_H
......@@ -20,6 +20,7 @@
%include "tokenreader.i"
%include "tokenwriter.i"
%include "libpwrnlperror.i"
%include "tagging.i"
%{
#include <libcorpus2/util/settings.h>
......
#ifndef SWIG_LIBCORPUS2_TAGGING_I
#define SWIG_LIBCORPUS2_TAGGING_I
%module libcorpustagging
%{
#include <libcorpus2/tagging.h>
%}
%include "std_string.i"
%include "tag.i"
%include "tagset.i"
namespace Corpus2 {
Tag get_attribute_mask(const Tagset& tagset,
const std::string attr_name);
}
using namespace std;
using namespace Corpus2;
#endif /* SWIG_LIBCORPUS2_TAGGING_I */
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment