LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
searchGraph.cpp
Go to the documentation of this file.
1// Copyright 2002-2019 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/************************************************************************
7 *
8 * @file searchGraph.cpp
9 * @author besancon (besanconr@zoe.cea.fr)
10 * @date Tue May 24 2005
11 * @version $Id$
12 * copyright Copyright (C) 2005-2019 by CEA LIST
13 *
14 ***********************************************************************/
15
16#include "searchGraph.h"
17
18using namespace std;
20
21namespace Lima {
22namespace LinguisticProcessing {
23namespace Automaton {
24
25//**********************************************************************
26// functions to walk the graph forward or backward
27//**********************************************************************
30
33 return new ForwardSearch();
34}
37 return new BackwardSearch();
38}
47
50 const LinguisticGraphVertex& current)
51{
52 m_current.push_back(make_pair(current,out_edges(current,*graph)));
53}
54
58{
59 if (m_current.back().second.first ==
60 m_current.back().second.second) {
61 return false;
62 }
63 else {
64 next=target(*(m_current.back().second.first),*graph);
65 m_current.back().second.first++;
66 return true;
67 }
68}
69
72 const LinguisticGraphVertex& current)
73{
74 m_current.push_back(make_pair(current,in_edges(current,*graph)));
75}
76
80{
81 if (m_current.back().second.first ==
82 m_current.back().second.second) {
83 return false;
84 }
85 else {
86 next=source(*(m_current.back().second.first),*graph);
87 m_current.back().second.first++;
88 return true;
89 }
90}
91
92#ifdef DEBUG_LP
93LIMA_AUTOMATON_EXPORT std::ostream& output(std::ostream& os, const BackwardSearch::Vertex2EdgePair& x, const LinguisticGraph* graph) {
94 LIMA_UNUSED(graph);
95 os << x.first << ":(" /*<< *(x.second.first) << "-" << *(x.second.second)*/ << ") ";
96 return os;
97}
98
99LIMA_AUTOMATON_EXPORT std::ostream& output(std::ostream& os, const BackwardSearch& x, const LinguisticGraph* graph) {
100 os << "bs{ ";
101 for (auto it = x.m_current.begin(); it != x.m_current.end(); it++)
102 output(os, *it, graph);;
103 os << " }";
104 return os;
105}
106
107LIMA_AUTOMATON_EXPORT std::ostream& output(std::ostream& os, const ForwardSearch::Vertex2EdgePair& x, const LinguisticGraph* graph) {
108 os << x.first << ":(" << target(*(x.second.first),*graph) << "-" << target(*(x.second.second),*graph) << ") ";
109 return os;
110}
111
112LIMA_AUTOMATON_EXPORT std::ostream& output(std::ostream& os, const ForwardSearch& x, const LinguisticGraph* graph) {
113 os << "fs{ ";
114 for (auto it = x.m_current.begin(); it != x.m_current.end(); it++)
115 output(os, *it, graph);
116 os << " }";
117 return os;
118}
119
120LIMA_AUTOMATON_EXPORT std::ostream& output(std::ostream& os, const SearchGraph *x, const LinguisticGraph* graph) {
121 const ForwardSearch *pForward = dynamic_cast<const ForwardSearch*>(x);
122 if (pForward != NULL) {
123 output(os, *pForward, graph);
124 return os;
125 }
126
127 const BackwardSearch *pBackward = dynamic_cast<const BackwardSearch*>(x);
128 if (pBackward != NULL)
129 output(os, *pBackward, graph);
130 else
131 {
132 AULOGINIT;
133 LIMA_EXCEPTION("Unexpected type of LinguisticGraph");
134 }
135 return os;
136}
137#endif
138
139} // end namespace
140} // end namespace
141} // end namespace
#define LIMA_AUTOMATON_EXPORT
#define LIMA_EXCEPTION(X)
This macro writes the message X to a previously configured error stream before throwing a LimaExcepti...
Definition LimaCommon.h:293
#define LIMA_UNUSED(x)
Definition LimaCommon.h:224
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
#define AULOGINIT
bool getNextVertex(const LinguisticGraph *graph, LinguisticGraphVertex &next) override
void findNextVertices(const LinguisticGraph *graph, const LinguisticGraphVertex &current) override
LinguisticGraphVertex endOfGraph(const LinguisticAnalysisStructure::AnalysisGraph &graph) override
std::pair< LinguisticGraphVertex, std::pair< LinguisticGraphInEdgeIt, LinguisticGraphInEdgeIt > > Vertex2EdgePair
Definition searchGraph.h:77
void findNextVertices(const LinguisticGraph *graph, const LinguisticGraphVertex &current) override
std::pair< LinguisticGraphVertex, std::pair< LinguisticGraphOutEdgeIt, LinguisticGraphOutEdgeIt > > Vertex2EdgePair
bool getNextVertex(const LinguisticGraph *graph, LinguisticGraphVertex &next) override
LinguisticGraphVertex endOfGraph(const LinguisticAnalysisStructure::AnalysisGraph &graph) override
An AnalysisData containing a LinguisticGraph with a language and an id.
const LinguisticGraphVertex & lastVertex(void) const
Returns the last vertex of the graph.
const LinguisticGraphVertex & firstVertex(void) const
Returns the first vertex of the graph.
NAUTITIA.
STL namespace.