From e7250075acb0f178ef5ea666f5817f40be1d4b01 Mon Sep 17 00:00:00 2001
From: ilor <kailoran@gmail.com>
Date: Wed, 27 Oct 2010 12:30:43 +0200
Subject: [PATCH] add Tagset get_pos_index(mask_t) and get_pos_name(mask_t pos)

---
 libcorpus2/tagset.cpp | 14 ++++++++++++++
 libcorpus2/tagset.h   |  9 ++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/libcorpus2/tagset.cpp b/libcorpus2/tagset.cpp
index 77b2260..b8957b9 100644
--- a/libcorpus2/tagset.cpp
+++ b/libcorpus2/tagset.cpp
@@ -420,6 +420,11 @@ const std::string& Tagset::get_pos_name(idx_t pos) const
 	return pos_dict_.get_string(pos);
 }
 
+const std::string& Tagset::get_pos_name(mask_t pos) const
+{
+	return pos_dict_.get_string(get_pos_index(pos));
+}
+
 mask_t Tagset::get_pos_mask(const string_range& pos) const
 {
 	return get_pos_mask(get_pos_index(pos));
@@ -434,6 +439,15 @@ mask_t Tagset::get_pos_mask(idx_t pos) const
 	}
 }
 
+idx_t Tagset::get_pos_index(mask_t pos) const
+{
+	if (pos.none()) {
+		return -1;
+	} else {
+		return PwrNlp::lowest_bit(pos);
+	}
+}
+
 idx_t Tagset::get_attribute_index(const string_range& a) const
 {
 	return attribute_dict_.get_id(a);
diff --git a/libcorpus2/tagset.h b/libcorpus2/tagset.h
index b2d4dcf..35768f0 100644
--- a/libcorpus2/tagset.h
+++ b/libcorpus2/tagset.h
@@ -266,7 +266,6 @@ public:
 		return attribute_dict_;
 	}
 
-
 	/// POS name -> index mapping
 	/// @returns -1 on invalid name
 	idx_t get_pos_index(const string_range& pos) const;
@@ -275,6 +274,10 @@ public:
 	/// @returns empty string on invalid index
 	const std::string& get_pos_name(idx_t pos) const;
 
+	/// POS mask -> name
+	/// @returns empty string on invalid index
+	const std::string& get_pos_name(mask_t pos) const;
+
 	/// POS name -> mask mapping
 	/// @return null mask on invalid name
 	mask_t get_pos_mask(const string_range& pos) const;
@@ -283,6 +286,10 @@ public:
 	/// @return null mask on invalid index
 	mask_t get_pos_mask(idx_t pos) const;
 
+	/// POS mask -> index mapping
+	/// @return -1 on empty mask, unspecified in more tha one POS set
+	idx_t get_pos_index(mask_t pos) const;
+
 
 	/// Attribute name -> index mapping
 	/// @returns -1 on invalid name
-- 
GitLab