Commit 56ca7a9a authored by Lionel's avatar Lionel

Feature/o3prm new type

parent 40583b06
......@@ -289,7 +289,7 @@ namespace gum {
*
* @param tick The tick value.
*/
virtual void addTick(double tick) override;
virtual void addTick( double tick ) override;
/**
* End the current discretized type declaration.
......
......@@ -1570,7 +1570,8 @@ namespace gum {
}
template <typename GUM_SCALAR>
INLINE void PRMFactory<GUM_SCALAR>::startDiscretizedType( const std::string& name ) {
INLINE void
PRMFactory<GUM_SCALAR>::startDiscretizedType( const std::string& name ) {
std::string real_name = __addPrefix( name );
if ( __prm->__typeMap.exists( real_name ) ) {
std::stringstream msg;
......
......@@ -870,10 +870,10 @@ namespace gum {
__nameMap[overloader->name()] = overloader;
__nameMap.insert( overloader->safeName(), overloader );
__referenceSlots.insert( overloader );
PRMSlotChain<GUM_SCALAR>* sc = 0;
PRMReferenceSlot<GUM_SCALAR>* ref = 0;
PRMClassElement<GUM_SCALAR>* next = 0;
std::vector<PRMSlotChain<GUM_SCALAR> *> toRemove, toAdd;
PRMSlotChain<GUM_SCALAR>* sc = 0;
PRMReferenceSlot<GUM_SCALAR>* ref = 0;
PRMClassElement<GUM_SCALAR>* next = 0;
std::vector<PRMSlotChain<GUM_SCALAR>*> toRemove, toAdd;
// Updating PRMSlotChain<GUM_SCALAR> which started with overloaded
for ( const auto slotchain : __slotChains ) {
......
......@@ -220,8 +220,9 @@ namespace gum {
/// @{
/// Code alias.
typedef typename HashTable<const PRMInstance<GUM_SCALAR>*,
EMap*>::iterator_safe EvidenceIterator;
typedef
typename HashTable<const PRMInstance<GUM_SCALAR>*, EMap*>::iterator_safe
EvidenceIterator;
/// Code alias.
typedef typename HashTable<const PRMInstance<GUM_SCALAR>*,
EMap*>::const_iterator_safe EvidenceConstIterator;
......
......@@ -125,8 +125,8 @@ namespace gum {
NodeId node,
BucketSet& pool,
BucketSet& trash ) {
Set<const PRMInstance<GUM_SCALAR> *> ignore, eliminated;
Set<NodeId> delayedVars;
Set<const PRMInstance<GUM_SCALAR>*> ignore, eliminated;
Set<NodeId> delayedVars;
// Downward elimination
List<const PRMInstance<GUM_SCALAR>*> elim_list;
ignore.insert( query );
......
......@@ -50,7 +50,7 @@ namespace gum {
// Retrieving the BN's variable
std::stringstream var_name;
var_name << chain.first->name() << "." << chain.second->safeName();
bn_obs->add(__inf->BN().variableFromName( var_name.str() ) );
bn_obs->add( __inf->BN().variableFromName( var_name.str() ) );
// Retrievin the PRM<GUM_SCALAR>'s evidence and copying it in bn_obs
const Potential<GUM_SCALAR>* prm_obs =
this->evidence( chain.first )[chain.second->id()];
......@@ -68,8 +68,7 @@ namespace gum {
const typename PRMInference<GUM_SCALAR>::Chain& chain ) {
std::stringstream var_name;
var_name << chain.first->name() << "." << chain.second->safeName();
const DiscreteVariable& var =
__inf->BN().variableFromName( var_name.str() );
const DiscreteVariable& var = __inf->BN().variableFromName( var_name.str() );
for ( auto iter = __obs.beginSafe(); iter != __obs.endSafe();
++iter ) { // safe iterator needed here
......
......@@ -911,13 +911,13 @@ namespace gum {
INLINE const PRMClassElement<GUM_SCALAR>*
O3ClassFactory<GUM_SCALAR>::__resolveSlotChain(
const PRMClassElementContainer<GUM_SCALAR>& c, const O3Label& chain ) {
auto s = chain.label();
auto current = &c;
auto s = chain.label();
auto current = &c;
std::vector<std::string> v;
decomposePath(chain.label(), v);
decomposePath( chain.label(), v );
for (size_t i=0;i<v.size();++i) {
for ( size_t i = 0; i < v.size(); ++i ) {
auto link = v[i];
if ( !__checkSlotChainLink( *current, chain, link ) ) {
......@@ -926,7 +926,7 @@ namespace gum {
auto elt = &( current->get( link ) );
if ( i == v.size() - 1) {
if ( i == v.size() - 1 ) {
// last link, should be an attribute or aggregate
return elt;
......
......@@ -95,6 +95,7 @@ namespace gum {
bool __isPrimitiveType( O3Type& type );
bool __checkO3Types();
void __checkDepreactedO3Types();
bool __addTypes2Dag();
bool __addArcs2Dag();
bool __checkLabels( O3Type& type );
......
......@@ -110,6 +110,8 @@ namespace gum {
}
__build = true;
// checking deprecated declarations
__checkDepreactedO3Types();
// building types
__buildTypes();
......@@ -149,6 +151,28 @@ namespace gum {
}
}
template <typename GUM_SCALAR>
INLINE void O3TypeFactory<GUM_SCALAR>::__checkDepreactedO3Types() {
for ( auto& t : __o3_prm->types() ) {
if ( t->deprecated() ) {
O3PRM_DEPRECATED_TYPE_WARNING( t->name(), *__errors );
}
}
for ( auto& t : __o3_prm->int_types() ) {
if ( t->deprecated() ) {
O3PRM_DEPRECATED_TYPE_WARNING( t->name(), *__errors );
}
}
for ( auto& t : __o3_prm->real_types() ) {
if ( t->deprecated() ) {
O3PRM_DEPRECATED_TYPE_WARNING( t->name(), *__errors );
}
}
}
template <typename GUM_SCALAR>
INLINE void O3TypeFactory<GUM_SCALAR>::__buildIntTypes() {
......@@ -159,7 +183,6 @@ namespace gum {
factory.addRangeType(
type->name().label(), type->start().value(), type->end().value() );
}
}
}
......
......@@ -287,13 +287,17 @@ namespace gum {
const std::string& O3Label::label() const { return __label; }
std::string& O3Label::label() { return __label; }
O3Type::O3Type() { GUM_CONSTRUCTOR( O3Type ); }
O3Type::O3Type()
: __dep_flag( false ) {
GUM_CONSTRUCTOR( O3Type );
}
O3Type::O3Type( const O3Type& src )
: __pos( src.__pos )
, __name( src.__name )
, __superLabel( src.__superLabel )
, __labels( src.__labels ) {
, __labels( src.__labels )
, __dep_flag( src.__dep_flag ) {
GUM_CONS_CPY( O3Type );
}
......@@ -301,7 +305,8 @@ namespace gum {
: __pos( std::move( src.__pos ) )
, __name( std::move( src.__name ) )
, __superLabel( std::move( src.__superLabel ) )
, __labels( std::move( src.__labels ) ) {
, __labels( std::move( src.__labels ) )
, __dep_flag( std::move( src.__dep_flag ) ) {
GUM_CONS_MOV( O3Type );
}
......@@ -315,6 +320,7 @@ namespace gum {
__name = src.__name;
__superLabel = src.__superLabel;
__labels = src.__labels;
__dep_flag = src.__dep_flag;
return *this;
}
......@@ -326,6 +332,7 @@ namespace gum {
__name = std::move( src.__name );
__superLabel = std::move( src.__superLabel );
__labels = std::move( src.__labels );
__dep_flag = std::move( src.__dep_flag );
return *this;
}
......@@ -341,13 +348,20 @@ namespace gum {
O3Position& O3Type::position() { return __pos; }
const O3Position& O3Type::position() const { return __pos; }
O3IntType::O3IntType() { GUM_CONSTRUCTOR( O3IntType ); }
bool& O3Type::deprecated() { return __dep_flag; }
const bool& O3Type::deprecated() const { return __dep_flag; }
O3IntType::O3IntType()
: __dep_flag( false ) {
GUM_CONSTRUCTOR( O3IntType );
}
O3IntType::O3IntType( const O3IntType& src )
: __pos( src.__pos )
, __name( src.__name )
, __start( src.__start )
, __end( src.__end ) {
, __end( src.__end )
, __dep_flag( src.__dep_flag ) {
GUM_CONS_CPY( O3IntType );
}
......@@ -355,7 +369,8 @@ namespace gum {
: __pos( std::move( src.__pos ) )
, __name( std::move( src.__name ) )
, __start( std::move( src.__start ) )
, __end( std::move( src.__end ) ) {
, __end( std::move( src.__end ) )
, __dep_flag( std::move( src.__dep_flag ) ) {
GUM_CONS_MOV( O3IntType );
}
......@@ -369,6 +384,7 @@ namespace gum {
__name = src.__name;
__start = src.__start;
__end = src.__end;
__dep_flag = src.__dep_flag;
return *this;
}
......@@ -380,6 +396,7 @@ namespace gum {
__name = std::move( src.__name );
__start = std::move( src.__start );
__end = std::move( src.__end );
__dep_flag = std::move( src.__dep_flag );
return *this;
}
......@@ -395,19 +412,27 @@ namespace gum {
O3Position& O3IntType::position() { return __pos; }
const O3Position& O3IntType::position() const { return __pos; }
O3RealType::O3RealType() { GUM_CONSTRUCTOR( O3RealType ); }
bool& O3IntType::deprecated() { return __dep_flag; }
const bool& O3IntType::deprecated() const { return __dep_flag; }
O3RealType::O3RealType()
: __dep_flag( false ) {
GUM_CONSTRUCTOR( O3RealType );
}
O3RealType::O3RealType( const O3RealType& src )
: __pos( src.__pos )
, __name( src.__name )
, __values( src.__values ) {
, __values( src.__values )
, __dep_flag( src.__dep_flag ) {
GUM_CONS_CPY( O3RealType );
}
O3RealType::O3RealType( O3RealType&& src )
: __pos( std::move( src.__pos ) )
, __name( std::move( src.__name ) )
, __values( std::move( src.__values ) ) {
, __values( std::move( src.__values ) )
, __dep_flag( std::move( src.__dep_flag ) ) {
GUM_CONS_MOV( O3RealType );
}
......@@ -421,6 +446,7 @@ namespace gum {
__pos = src.__pos;
__name = src.__name;
__values = src.__values;
__dep_flag = src.__dep_flag;
return *this;
}
......@@ -432,20 +458,22 @@ namespace gum {
__pos = std::move( src.__pos );
__name = std::move( src.__name );
__values = std::move( src.__values );
__dep_flag = std::move( src.__dep_flag );
return *this;
}
O3Position& O3RealType::position() { return __pos; }
const O3Position& O3RealType::position() const { return __pos; }
O3Label& O3RealType::name() { return __name; }
O3Label& O3RealType::name() { return __name; }
const O3Label& O3RealType::name() const { return __name; }
std::vector<O3Float>& O3RealType::values() { return __values; }
std::vector<O3Float>& O3RealType::values() { return __values; }
const std::vector<O3Float>& O3RealType::values() const { return __values; }
bool& O3RealType::deprecated() { return __dep_flag; }
const bool& O3RealType::deprecated() const { return __dep_flag; }
O3PRM::O3PRM() {
GUM_CONSTRUCTOR( O3PRM );
// Creating the boolean type
......
......@@ -224,11 +224,15 @@ namespace gum {
LabelMap& labels();
const LabelMap& labels() const;
bool& deprecated();
const bool& deprecated() const;
private:
O3Position __pos;
O3Label __name;
O3Label __superLabel;
LabelMap __labels;
bool __dep_flag;
};
/**
......@@ -260,11 +264,15 @@ namespace gum {
O3Integer& end();
const O3Integer& end() const;
bool& deprecated();
const bool& deprecated() const;
private:
O3Position __pos;
O3Label __name;
O3Integer __start;
O3Integer __end;
bool __dep_flag;
};
/**
......@@ -293,10 +301,14 @@ namespace gum {
std::vector<O3Float>& values();
const std::vector<O3Float>& values() const;
bool& deprecated();
const bool& deprecated() const;
private:
O3Position __pos;
O3Label __name;
std::vector<O3Float> __values;
bool __dep_flag;
};
/**
......
......@@ -116,14 +116,14 @@ namespace gum {
__bn->variable( node ).setDescription( nn );
// trying to simplify the name
auto start = nn.find_first_of('(');
auto end = nn.find_first_of(')');
if (0 < start && start < end && end < nn.size()) {
auto path = nn.substr(0, start);
auto type = nn.substr(start + 1, end-start-1);
auto name = nn.substr(end + 1, std::string::npos);
std::string newNameRadical = __getVariableName( path, type, name);
auto start = nn.find_first_of( '(' );
auto end = nn.find_first_of( ')' );
if ( 0 < start && start < end && end < nn.size() ) {
auto path = nn.substr( 0, start );
auto type = nn.substr( start + 1, end - start - 1 );
auto name = nn.substr( end + 1, std::string::npos );
std::string newNameRadical = __getVariableName( path, type, name );
std::string newName = newNameRadical;
// forcing newName to be unique
......
......@@ -36,18 +36,18 @@
#include <string>
#include <vector>
#include <agrum/config.h>
#include <agrum/core/errorsContainer.h>
#include <agrum/core/utils_string.h>
#include <agrum/PRM/o3prm/cocoR/Parser.h>
#include <agrum/PRM/o3prm/cocoR/Scanner.h>
#include <agrum/PRM/PRM.h>
#include <agrum/PRM/o3prm/O3ClassFactory.h>
#include <agrum/PRM/o3prm/O3InterfaceFactory.h>
#include <agrum/PRM/o3prm/O3NameSolver.h>
#include <agrum/PRM/o3prm/O3prm.h>
#include <agrum/PRM/o3prm/O3SystemFactory.h>
#include <agrum/PRM/o3prm/O3TypeFactory.h>
#include <agrum/PRM/PRM.h>
#include <agrum/PRM/o3prm/O3prm.h>
#include <agrum/PRM/o3prm/cocoR/Parser.h>
#include <agrum/PRM/o3prm/cocoR/Scanner.h>
#include <agrum/config.h>
#include <agrum/core/errorsContainer.h>
#include <agrum/core/utils_string.h>
namespace gum {
namespace prm {
......
......@@ -36,70 +36,70 @@ namespace gum {
O3prmReader<GUM_SCALAR>::__clean( std::string text ) const {
// This could be way more faster with regex but there are not implemented
// with gcc-4.8 !
text = replace(text, "Syntax error", "Error");
text = replace(text, "LABEL_OR_STAR_LIST", "declaration");
text = replace(text, "ARRAY_REFERENCE_SLOT", "declaration");
text = replace(text, "FLOAT_AS_LABEL", "declaration");
text = replace(text, "FLOAT_OR_INT", "declaration");
text = replace(text, "INTEGER_AS_FLOAT", "declaration");
text = replace(text, "INTEGER_AS_LABEL", "declaration");
text = replace(text, "INT_TYPE_DECLARATION", "declaration");
text = replace(text, "LABEL_OR_INT", "declaration");
text = replace(text, "LABEL_OR_STAR", "declaration");
text = replace(text, "NAMED_CLASS_ELEMENT", "declaration");
text = replace(text, "REAL_TYPE_DECLARATION", "declaration");
text = replace(text, "AGGREGATE_PARENTS", "declaration");
text = replace(text, "CLASS_BODY", "declaration");
text = replace(text, "CLASS_DECLARATION", "declaration");
text = replace(text, "CLASS_ELEMENT", "declaration");
text = replace(text, "CLASS_PARAMETER", "declaration");
text = replace(text, "CLASS_UNIT", "declaration");
text = replace(text, "FLOAT_LIST", "declaration");
text = replace(text, "FORMULA_LIST", "declaration");
text = replace(text, "IDENTIFIER_LIST", "declaration");
text = replace(text, "IMPORT_BODY", "declaration");
text = replace(text, "IMPORT_DECLARATION", "declaration");
text = replace(text, "IMPORT_UNIT", "declaration");
text = replace(text, "INTERFACE_BODY", "declaration");
text = replace(text, "INTERFACE_DECLARATION", "declaration");
text = replace(text, "INTERFACE_UNIT", "declaration");
text = replace(text, "LABEL_LIST", "declaration");
text = replace(text, "PARAMETER_LIST", "declaration");
text = replace(text, "PREFIXED_LABEL", "declaration");
text = replace(text, "RAW_CPT", "declaration");
text = replace(text, "REFERENCE_SLOT", "declaration");
text = replace(text, "RULE_CPT", "declaration");
text = replace(text, "SYSTEM_BODY", "declaration");
text = replace(text, "SYSTEM_DECLARATION", "declaration");
text = replace(text, "SYSTEM_UNIT", "declaration");
text = replace(text, "TYPE_DECLARATION", "declaration");
text = replace(text, "TYPE_LABEL", "declaration");
text = replace(text, "TYPE_UNIT", "declaration");
text = replace(text, "TYPE_VALUE_LIST", "declaration");
text = replace(text, "AGGREGATE", "declaration");
text = replace(text, "ARRAY", "declaration");
text = replace(text, "ATTRIBUTE", "declaration");
text = replace(text, "CAST", "declaration");
text = replace(text, "CHAIN", "declaration");
text = replace(text, "CLASS", "declaration");
text = replace(text, "FLOAT", "declaration");
text = replace(text, "FORMULA", "declaration");
text = replace(text, "IDENTIFIER", "declaration");
text = replace(text, "INT", "declaration");
text = replace(text, "INTEGER", "declaration");
text = replace(text, "INTERFACE", "declaration");
text = replace(text, "LABEL", "declaration");
text = replace(text, "LINK", "declaration");
text = replace(text, "MAP", "declaration");
text = replace(text, "PARAMETER", "declaration");
text = replace(text, "REAL", "declaration");
text = replace(text, "RULE", "declaration");
text = replace(text, "TYPE", "declaration");
text = replace(text, "UNIT", "declaration");
text = replace( text, "Syntax error", "Error" );
text = replace( text, "LABEL_OR_STAR_LIST", "declaration" );
text = replace( text, "ARRAY_REFERENCE_SLOT", "declaration" );
text = replace( text, "FLOAT_AS_LABEL", "declaration" );
text = replace( text, "FLOAT_OR_INT", "declaration" );
text = replace( text, "INTEGER_AS_FLOAT", "declaration" );
text = replace( text, "INTEGER_AS_LABEL", "declaration" );
text = replace( text, "INT_TYPE_DECLARATION", "declaration" );
text = replace( text, "LABEL_OR_INT", "declaration" );
text = replace( text, "LABEL_OR_STAR", "declaration" );
text = replace( text, "NAMED_CLASS_ELEMENT", "declaration" );
text = replace( text, "REAL_TYPE_DECLARATION", "declaration" );
text = replace( text, "AGGREGATE_PARENTS", "declaration" );
text = replace( text, "CLASS_BODY", "declaration" );
text = replace( text, "CLASS_DECLARATION", "declaration" );
text = replace( text, "CLASS_ELEMENT", "declaration" );
text = replace( text, "CLASS_PARAMETER", "declaration" );
text = replace( text, "CLASS_UNIT", "declaration" );
text = replace( text, "FLOAT_LIST", "declaration" );
text = replace( text, "FORMULA_LIST", "declaration" );
text = replace( text, "IDENTIFIER_LIST", "declaration" );
text = replace( text, "IMPORT_BODY", "declaration" );
text = replace( text, "IMPORT_DECLARATION", "declaration" );
text = replace( text, "IMPORT_UNIT", "declaration" );
text = replace( text, "INTERFACE_BODY", "declaration" );
text = replace( text, "INTERFACE_DECLARATION", "declaration" );
text = replace( text, "INTERFACE_UNIT", "declaration" );
text = replace( text, "LABEL_LIST", "declaration" );
text = replace( text, "PARAMETER_LIST", "declaration" );
text = replace( text, "PREFIXED_LABEL", "declaration" );
text = replace( text, "RAW_CPT", "declaration" );
text = replace( text, "REFERENCE_SLOT", "declaration" );
text = replace( text, "RULE_CPT", "declaration" );
text = replace( text, "SYSTEM_BODY", "declaration" );
text = replace( text, "SYSTEM_DECLARATION", "declaration" );
text = replace( text, "SYSTEM_UNIT", "declaration" );
text = replace( text, "TYPE_DECLARATION", "declaration" );
text = replace( text, "TYPE_LABEL", "declaration" );
text = replace( text, "TYPE_UNIT", "declaration" );
text = replace( text, "TYPE_VALUE_LIST", "declaration" );
text = replace( text, "AGGREGATE", "declaration" );
text = replace( text, "ARRAY", "declaration" );
text = replace( text, "ATTRIBUTE", "declaration" );
text = replace( text, "CAST", "declaration" );
text = replace( text, "CHAIN", "declaration" );
text = replace( text, "CLASS", "declaration" );
text = replace( text, "FLOAT", "declaration" );
text = replace( text, "FORMULA", "declaration" );
text = replace( text, "IDENTIFIER", "declaration" );
text = replace( text, "INT", "declaration" );
text = replace( text, "INTEGER", "declaration" );
text = replace( text, "INTERFACE", "declaration" );
text = replace( text, "LABEL", "declaration" );
text = replace( text, "LINK", "declaration" );
text = replace( text, "MAP", "declaration" );
text = replace( text, "PARAMETER", "declaration" );
text = replace( text, "REAL", "declaration" );
text = replace( text, "RULE", "declaration" );
text = replace( text, "TYPE", "declaration" );
text = replace( text, "UNIT", "declaration" );
return text;
}
......@@ -269,7 +269,9 @@ namespace gum {
O3prmReader<GUM_SCALAR>::showElegantErrors( std::ostream& o ) const {
for ( Idx i = 0; i < __errors.count(); ++i ) {
auto err = __errors.error( i );
o << __print( err ) << std::endl;
if ( err.is_error ) {
o << __print( err ) << std::endl;
}
}
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -600,6 +600,15 @@ namespace gum {
errors.addError( msg.str(), pos.file(), pos.line(), pos.column() );
}
void O3PRM_DEPRECATED_TYPE_WARNING( const O3Label& val,
ErrorsContainer& errors ) {
const auto& pos = val.position();
std::stringstream msg;
msg << "Warning : " << val.label()
<< " is declared using a deprecated syntax.";
errors.addWarning( msg.str(), pos.file(), pos.line(), pos.column() );
}
} // o3prm
} // prm
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment