LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
automatonCommon.cpp
Go to the documentation of this file.
1// Copyright 2002-2020 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/************************************************************************
7 *
8 * @file automatonCommon.cpp
9 * @author besancon (besanconr@zoe.cea.fr)
10 * @date Tue Mar 22 2005
11 * @version $Id$
12 * copyright Copyright (C) 2005-2020 by CEA LIST
13 *
14 ***********************************************************************/
15
16#include "automatonCommon.h"
18
19#include <cmath>
20
21using namespace Lima::Common;
22
23namespace Lima
24{
25namespace LinguisticProcessing
26{
27namespace Automaton
28{
29
30// utility function for conversion of limastring to int
32{
33 return s.toUInt();
34}
35
36//----------------------------------------------------------------------
37// Tword type
38void readTword(std::ifstream& file, Tword& s,FsaStringsPool& sp)
39{
40 LimaString str;
42 s=sp[str];
43}
44void writeTword(std::ofstream& file,const Tword& s,const FsaStringsPool& sp)
45{
47}
48
49// LimaString type
50void readLimaString(std::ifstream& file, LimaString& s)
51{
53}
54void writeLimaString(std::ofstream& file,const LimaString& s)
55{
57}
58
59// wordSet = set of multi-term
60void readWordVector(std::ifstream& file, std::vector<LimaString>& wordVector)
61{
62 auto i = Misc::readCodedInt(file);
63 for( ; i > 0 ; i-- ) {
64 LimaString s;
66 wordVector.push_back(s);
67 }
68}
69
70void writeWordSet(std::ofstream& file,const std::set<LimaString>& wordSet)
71{
72 int i = wordSet.size();
73 Misc::writeCodedInt(file,i);
74 std::set<LimaString>::const_iterator wordIt = wordSet.begin();
75 for( ; wordIt != wordSet.end() ; wordIt++ ) {
76 Misc::writeUTF8StringField(file,*wordIt);
77 }
78}
79
80//----------------------------------------------------------------------
81// Part-of-speech type
82void readTpos(std::ifstream& file, Tpos& p)
83{
85}
86void writeTpos(std::ofstream& file, const Tpos& p)
87{
89}
90
91bool compareTpos(const Tpos& pos, const LinguisticCode& lingProperty,
92 const PropertyCode::PropertyAccessor& macroAccessor,
93 const PropertyCode::PropertyAccessor& microAccessor)
94{
95 return ( (microAccessor.equal(lingProperty,pos)) ||
96 (microAccessor.empty(pos) &&
97 macroAccessor.equal(lingProperty,pos)));
98}
99
100} // end namespace
101} // end namespace
102} // end namespace
Provide function to read write and check a property.
bool equal(const LinguisticCode &l1, const LinguisticCode &l2) const
check property equality for two linguisticCode
bool empty(const LinguisticCode &l) const
Test if the given code has property data.
static std::ostream & encodeToBinary(std::ostream &os, const LinguisticCode &value)
Definition StdBitset.h:173
static LinguisticCode decodeFromBinary(std::istream &is)
Definition StdBitset.h:197
void writeUTF8StringField(std::ostream &file, const Lima::LimaString &s)
Binary write a a LimaString in a file as an utf8 string.
uint64_t readCodedInt(std::istream &file)
read a integer coded in variable-byte format in a file
void readUTF8StringField(std::istream &file, Lima::LimaString &s)
Binary read an utf8 string from a file and store it in a LimaString.
void writeCodedInt(std::ostream &file, const uint64_t number)
write a integer coded in variable-byte format in a file
bool compareTpos(const Tpos &pos, const LinguisticCode &lingProperty, const PropertyCode::PropertyAccessor &macroAccessor, const PropertyCode::PropertyAccessor &microAccessor)
void writeTpos(std::ofstream &file, const Tpos &p)
void readTword(std::ifstream &file, Tword &s, FsaStringsPool &sp)
void readTpos(std::ifstream &file, Tpos &p)
void writeLimaString(std::ofstream &file, const LimaString &s)
void readWordVector(std::ifstream &file, std::vector< LimaString > &wordVector)
void writeTword(std::ofstream &file, const Tword &s, const FsaStringsPool &sp)
void writeWordSet(std::ofstream &file, const std::set< LimaString > &wordSet)
void readLimaString(std::ifstream &file, LimaString &s)
NAUTITIA.
QString LimaString
Definition LimaString.h:33