strusAnalyzer  0.17
documentTerm.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
10 #ifndef _STRUS_ANALYZER_DOCUMENT_TERM_HPP_INCLUDED
11 #define _STRUS_ANALYZER_DOCUMENT_TERM_HPP_INCLUDED
12 #include <string>
13 #include <vector>
14 
16 namespace strus {
18 namespace analyzer {
19 
22 {
23 public:
24  typedef int Position;
25 
28  :m_type(),m_value(),m_pos(0){}
30 #if __cplusplus >= 201103L
31  DocumentTerm( DocumentTerm&& ) = default;
32  DocumentTerm( const DocumentTerm& ) = default;
33  DocumentTerm& operator= ( DocumentTerm&& ) = default;
34  DocumentTerm& operator= ( const DocumentTerm& ) = default;
35 #else
37  :m_type(o.m_type),m_value(o.m_value),m_pos(o.m_pos){}
38 #endif
39  DocumentTerm( const std::string& t, const std::string& v, const Position& p)
45  :m_type(t),m_value(v),m_pos(p){}
46 
49  const std::string& type() const {return m_type;}
52  const std::string& value() const {return m_value;}
55  Position pos() const {return m_pos;}
56 
59  void setPos( const Position& pos_) {m_pos = pos_;}
60 
61  bool operator < (const DocumentTerm& o) const
62  {
63  if (m_pos == o.m_pos)
64  {
65  return (m_type == o.m_type)
66  ? m_value < o.m_value
67  : m_type < o.m_type;
68  }
69  else
70  {
71  return m_pos < o.m_pos;
72  }
73  }
74 
75  bool defined() const
76  {
77  return !!m_pos;
78  }
79 
80  void clear()
81  {
82  m_type.clear();
83  m_value.clear();
84  m_pos = 0;
85  }
86 
87 private:
88  std::string m_type;
89  std::string m_value;
90  Position m_pos;
91 };
92 
93 }}//namespace
94 #endif
95 
void setPos(const Position &pos_)
Set the ordinal position of the term.
Definition: documentTerm.hpp:59
int Position
Definition: documentTerm.hpp:24
bool operator<(const DocumentTerm &o) const
Definition: documentTerm.hpp:61
DocumentTerm(const DocumentTerm &o)
Copy constructor.
Definition: documentTerm.hpp:36
DocumentTerm()
Default constructor.
Definition: documentTerm.hpp:27
const std::string & type() const
Get the type name of the term.
Definition: documentTerm.hpp:49
Position pos() const
Get the ordinal position of the term.
Definition: documentTerm.hpp:55
void clear()
Definition: documentTerm.hpp:80
Structure describing a position in a document source by segment and offset.
Definition: position.hpp:22
const std::string & value() const
Get the value of the term.
Definition: documentTerm.hpp:52
bool defined() const
Definition: documentTerm.hpp:75
Structure describing a typed document term.
Definition: documentTerm.hpp:21