2015-05-04 20:40:44 +02:00
|
|
|
#include <concordia/concordia.hpp>
|
|
|
|
#include <concordia/concordia_search_result.hpp>
|
|
|
|
#include <concordia/matched_pattern_fragment.hpp>
|
|
|
|
#include <concordia/example.hpp>
|
2015-06-27 12:40:24 +02:00
|
|
|
#include <concordia/tokenized_sentence.hpp>
|
2015-05-04 20:40:44 +02:00
|
|
|
|
|
|
|
#include "config.hpp"
|
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
Concordia concordia(EXAMPLES_DIR"/../tests/resources/concordia-config/concordia.cfg");
|
|
|
|
|
2015-08-24 14:30:20 +02:00
|
|
|
TokenizedSentence ts = concordia.addExample(Example("Alice has a cat", 56));
|
2015-06-27 12:40:24 +02:00
|
|
|
cout << "Added the following tokens: " << endl;
|
2015-08-24 14:30:20 +02:00
|
|
|
BOOST_FOREACH(TokenAnnotation token, ts.getTokens()) {
|
2015-06-27 12:40:24 +02:00
|
|
|
cout << "\"" << token.getValue() << "\"" << " at positions: [" << token.getStart() << ","
|
|
|
|
<< token.getEnd() << ")" << endl;
|
|
|
|
}
|
|
|
|
|
2015-05-04 20:40:44 +02:00
|
|
|
concordia.addExample(Example("Alice has a dog", 23));
|
|
|
|
concordia.addExample(Example("New test product has a mistake", 321));
|
|
|
|
concordia.addExample(Example("This is just testing and it has nothing to do with the above", 14));
|
|
|
|
|
|
|
|
concordia.refreshSAfromRAM();
|
|
|
|
|
|
|
|
cout << "Searching for pattern: Our new test product has nothing to do with computers" << endl;
|
|
|
|
boost::shared_ptr<ConcordiaSearchResult> result =
|
|
|
|
concordia.concordiaSearch("Our new test product has nothing to do with computers");
|
|
|
|
|
|
|
|
cout << "Printing all matched fragments:" << endl;
|
|
|
|
BOOST_FOREACH(MatchedPatternFragment fragment, result->getFragments()) {
|
|
|
|
cout << "Matched pattern fragment found. Pattern fragment: ["
|
|
|
|
<< fragment.getStart() << "," << fragment.getEnd() << "]"
|
|
|
|
<< " in sentence " << fragment.getExampleId()
|
|
|
|
<< ", at offset: " << fragment.getExampleOffset() << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cout << "Best overlay:" << endl;
|
|
|
|
BOOST_FOREACH(MatchedPatternFragment fragment, result->getBestOverlay()) {
|
|
|
|
cout << "\tPattern fragment: [" << fragment.getStart()
|
|
|
|
<< "," << fragment.getEnd() << "]"
|
|
|
|
<< " in sentence " << fragment.getExampleId()
|
|
|
|
<< ", at offset: " << fragment.getExampleOffset() << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << "Best overlay score: " << result->getBestOverlayScore() << endl;
|
|
|
|
|
|
|
|
// clearing index
|
|
|
|
concordia.clearIndex();
|
|
|
|
}
|