LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
TokenFilter.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/******************************************************************************
7*
8* File : tokenFilter.cpp
9* Author : Gael de Chalendar (Gael.de-Chalendar@cea.fr)
10* Created on : Mon Aug 04 2003
11* Copyright : (c) 2003 by CEA
12* Version : $Id$
13*
14******************************************************************************/
15
16#include "TokenFilter.h"
18
20
21namespace Lima {
22namespace LinguisticProcessing {
23namespace SyntacticAnalysis {
24
25TokenFilter::TokenFilter(const std::string& id, const std::string& name,
26 const std::set< StringsPoolIndex >& attributes,
27 const std::set< LinguisticCode >& categories) :
28 m_id(id), m_name(name), m_attributes(attributes), m_categories(categories)
29{
30}
31
33 m_id(filter.m_id), m_name(filter.m_name),
34 m_attributes(filter.m_attributes), m_categories(filter.m_categories)
35{
36}
37
39 const Common::PropertyCode::PropertyAccessor* microAccessor) :
40 m_id(),
41 m_name(),
42 m_attributes(data->allNormalizedForms()),
43 m_categories(data->allValues(*microAccessor))
44{}
45
47{
48 m_attributes.clear();
49 m_categories.clear();
50}
51
53{
54 m_id = filter.m_id;
55 m_name = filter.m_name;
56 m_attributes = filter.m_attributes;
57 m_categories = filter.m_categories;
58}
59
60bool TokenFilter::operator==(const TokenFilter& filter) const
61{
62 return ( (m_id == filter.m_id) && (m_name == filter.m_name) &&
63 (m_attributes == filter.m_attributes) && (m_categories == filter.m_categories) );
64}
65
66/*
67bool TokenFilter::operator==(const DicoWord& word) const
68{
69 bool checkAttributes;
70 bool checkCategories;
71
72 if (m_attributes.size() == 0) checkAttributes = true;
73 else checkAttributes = (m_attributes.find(word.lemmaIndex()) != m_attributes.end());
74 checkCategories = (m_categories.find(word.microCategory()) != m_categories.end());
75 return ( checkAttributes && checkCategories );
76}
77*/
78
80bool tfless::operator()(const TokenFilter& x, const TokenFilter& y) const
81{
82// std::cerr << "In tfless(" << x << ", " << y << ")..." << std::endl;
83 if ( (x.id() != "") && (y.id() != "") ) {
84 return (x.id() < y.id());
85 } else if (x.attributes() != y.attributes()) {
86 return (x.attributes() < y.attributes());
87 } else {
88 return (x.categories() < y.categories());
89 }
90}
91
92std::ostream& operator<<(std::ostream &os, const TokenFilter& d)
93{
94 os << d.id() << " ";
95 os << d.name() << " " ;
96 std::set< StringsPoolIndex >::const_iterator it_attr, it_attr_end;
97 boost::tie(it_attr, it_attr_end) = d.attributesIterators();
98 for (; it_attr != it_attr_end; it_attr++)
99 {
100
101 // language not available, write stringPoolIndexes instead of string, to be fixed later
102 os << *it_attr << " ";
103 }
104 std::set< LinguisticCode >::const_iterator it_cat, it_cat_end;
105 boost::tie(it_cat, it_cat_end) = d.categoriesIterators();
106 for (; it_cat != it_cat_end; it_cat++)
107 os << (*it_cat) << " ";
108 return os;
109}
110
111} // namespace SyntacticAnalysis
112} // namespace LinguisticProcessing
113} // namespace Lima
Provide function to read write and check a property.
std::pair< std::set< StringsPoolIndex >::iterator, std::set< StringsPoolIndex >::iterator > attributesIterators()
std::pair< std::set< LinguisticCode >::iterator, std::set< LinguisticCode >::iterator > categoriesIterators()
bool operator==(const TokenFilter &filter) const
bool operator()(const TokenFilter &x, const TokenFilter &y) const
Used to search a real TokenFilter inside syntagmatic structure.
std::ostream & operator<<(std::ostream &os, const Key &k)
Operators to dump to stream the classes defined here.
NAUTITIA.