#include <LingFeatures.h>
Public Types | |
typedef std::set< const LingDef::Feature * > | FeaturesList |
typedef FeaturesList::const_iterator | FeatureIterator |
typedef std::multimap< const LingDef::Feature *, const LingDef::Feature * > | EnumMap |
typedef std::multimap< const LingDef::Feature *, int > | ReferenceMap |
Public Member Functions | |
LingFeatures (const LingDef::Pos &posDef) | |
~LingFeatures () | |
LingFeatures (const LingDef &lingDef) | |
The pos definition must be set using setPosDef() before using the object. | |
const LingDef * | getLingDef () const |
Returns the LingDef object for which this object is created. | |
const LingDef::Pos * | getPosDef () const |
Returns the pos definition for which this LingFeatures object is created. | |
void | setPosDef (const LingDef::Pos &) |
Sets the pos definition for which this object will be defined. | |
const std::string & | getLemma () const |
void | setLemma (const std::string &) |
const std::string & | getForm () const |
void | setForm (const std::string &) |
void | set (const std::string &feature) |
Sets the feature with the name feature . | |
void | setNegative (const std::string &feature) |
void | unset (const std::string &feature) |
Unsets the feature with the name feature . | |
bool | has (const std::string &feature) const |
Returns wether or not the feature with the name feature is set. | |
bool | hasNegative (const std::string &feature) const |
bool | isDefined (const std::string &feature) const |
void | set (const LingDef::Feature &) |
Same as set(string), except the lookup step in the parent LingDef is skipped. | |
void | setNegative (const LingDef::Feature &) |
void | unset (const LingDef::Feature &) |
Same as unset(string), except the lookup step in the parent LingDef is skipped. | |
bool | has (const LingDef::Feature &) const |
Same as has(string), except the lookup step in the parent LingDef is skipped. | |
bool | hasNegative (const LingDef::Feature &) const |
Same as hasNegative(string), except the lookup step in the parent LingDef is skipped. | |
bool | isDefined (const LingDef::Feature &) const |
const LingFeatures & | operator+= (const std::string &) |
Same as set(std::string &). | |
const LingFeatures & | operator+= (const LingDef::Feature &) |
Same as set(LingDef::Feature &). | |
const LingFeatures & | operator-= (const std::string &) |
Same as setNegative(std::string &). | |
const LingFeatures & | operator-= (const LingDef::Feature &) |
Same as setNegative(LingDef::Feature &). | |
void | setReference (const std::string &feature, int) |
Sets the value of the reference feature by the name of feature . | |
int | getReference (const std::string &feature) const |
Returns the value of the reference feature by the name of feature . | |
void | getReferenceList (const std::string &feature, std::vector< int > &) const |
Returns a list containing the values for the reference feature by the name of feature . | |
bool | hasReference (const std::string &feature, int referenceValue) const |
Returns the value of the reference feature by the name of feature is referenceValue . | |
void | setReference (const LingDef::Feature &, int) |
int | getReference (const LingDef::Feature &) const |
void | getReferenceList (const LingDef::Feature &, std::vector< int > &) const |
bool | hasReference (const LingDef::Feature &, int) const |
void | setEnum (const std::string &enumFeature, const std::string &valueFeature) |
void | setEnum (const LingDef::Feature &enumFeature, const LingDef::Feature &valueFeature) |
const LingDef::Feature * | getEnumValue (const std::string &) const |
const LingDef::Feature * | getEnumValue (const LingDef::Feature &) const |
void | getEnumValues (const std::string &, std::set< const LingDef::Feature * > &) const |
void | getEnumValues (const LingDef::Feature &, std::set< const LingDef::Feature * > &) const |
int | hasEnumValue (const std::string &enumValueName) const |
int | hasEnumValue (const LingDef::Feature &enumValueFeature) const |
bool | covers (const LingFeatures &) const |
This LingFeatures object covers another LingFeatures object if all the features in the other LingFeatures object are present in this LingFeatures object. | |
void | execute (const std::string &) |
Sets and unsets features as defined by a string on the form. | |
void | setDefaults () |
void | setDefaultForEnum (const LingDef::Feature &enumFeature) |
FeatureIterator | featuresBegin () const |
FeatureIterator | featuresEnd () const |
Protected Member Functions | |
LingFeatures () | |
Dangerous! | |
Friends | |
class | LingDef |
Classes | |
class | Exception |
TODO. More... |
The only mandatory information needed to create this instance is the pos.
Features can be added, removed and checked:
features.set("plural");
features.set("masculine");
features.has("number"); // Returns true, if 'plural' is an enumeration
// value of 'number'
features.unset("plural");
features.has("number"); // Returns false
features.unset("gender");
features.has("masculine"); // Returns false
This assuming that the pos for which the object features
is created has an enumeration number
containing singular
and plural
, and another called gender
containing masculine
and feminine
.
There are also two fix string properties for a LingFeatures object, lemma and form. Having them among the linguistic properties allows for a good abstraction of a word being a LingFeatures object.
Definition at line 54 of file LingFeatures.h.
typedef std::multimap<const LingDef::Feature *, const LingDef::Feature *> LinguisticDefinition::LingFeatures::EnumMap |
Definition at line 414 of file LingFeatures.h.
typedef FeaturesList::const_iterator LinguisticDefinition::LingFeatures::FeatureIterator |
Definition at line 398 of file LingFeatures.h.
typedef std::set<const LingDef::Feature *> LinguisticDefinition::LingFeatures::FeaturesList |
Definition at line 393 of file LingFeatures.h.
typedef std::multimap<const LingDef::Feature *, int> LinguisticDefinition::LingFeatures::ReferenceMap |
Definition at line 419 of file LingFeatures.h.
LingFeatures::LingFeatures | ( | const LingDef::Pos & | posDef | ) |
posDef | The pos definition to instantiate. Note that the pos definition contains the reference to a LingDef object, so there is no need to specify that here. |
Definition at line 31 of file LingFeatures.cc.
References setDefaults().
LingFeatures::~LingFeatures | ( | ) |
Definition at line 17 of file LingFeatures.cc.
LingFeatures::LingFeatures | ( | const LingDef & | lingDef | ) |
The pos definition must be set using setPosDef() before using the object.
Definition at line 23 of file LingFeatures.cc.
LingFeatures::LingFeatures | ( | ) | [protected] |
bool LingFeatures::covers | ( | const LingFeatures & | ) | const |
This LingFeatures object covers another LingFeatures object if all the features in the other LingFeatures object are present in this LingFeatures object.
Example:
a.set("plural");
a.set("masculine");
b.set("plural");
c.set("plural");
c.set("feminine");
a.covers(a); // true
a.covers(b); // true
b.covers(a); // false
a.covers(c); // false
c.covers(b); // true
Definition at line 661 of file LingFeatures.cc.
void LingFeatures::execute | ( | const std::string & | ) |
Sets and unsets features as defined by a string on the form.
+definite+gender=masculine-number+modified_by=$2
which would correspond to
features.set("definite");
features.set("masculine");
features.unset("number");
features.setReference("modified_by", 2);
Definition at line 62 of file LingFeatures.cc.
References set(), setNegative(), and setReference().
LingFeatures::FeatureIterator LingFeatures::featuresBegin | ( | ) | const |
Definition at line 682 of file LingFeatures.cc.
Referenced by LinguisticDefinition::XmlLingFeaturesFormatter::output().
LingFeatures::FeatureIterator LingFeatures::featuresEnd | ( | ) | const |
Definition at line 689 of file LingFeatures.cc.
Referenced by LinguisticDefinition::XmlLingFeaturesFormatter::output().
const LingDef::Feature * LingFeatures::getEnumValue | ( | const LingDef::Feature & | ) | const |
Definition at line 518 of file LingFeatures.cc.
const LingDef::Feature* LinguisticDefinition::LingFeatures::getEnumValue | ( | const std::string & | ) | const |
void LingFeatures::getEnumValues | ( | const LingDef::Feature & | , | |
std::set< const LingDef::Feature * > & | ||||
) | const |
Definition at line 545 of file LingFeatures.cc.
void LinguisticDefinition::LingFeatures::getEnumValues | ( | const std::string & | , | |
std::set< const LingDef::Feature * > & | ||||
) | const |
Referenced by hasEnumValue(), and LinguisticDefinition::XmlLingFeaturesFormatter::output().
const std::string & LingFeatures::getForm | ( | ) | const |
Definition at line 740 of file LingFeatures.cc.
Referenced by LinguisticDefinition::WordPattern::LeafElement::matches(), and LinguisticDefinition::XmlLingFeaturesFormatter::output().
const std::string & LingFeatures::getLemma | ( | ) | const |
Definition at line 726 of file LingFeatures.cc.
Referenced by LinguisticDefinition::WordPattern::LeafElement::matches(), and LinguisticDefinition::XmlLingFeaturesFormatter::output().
const LingDef * LingFeatures::getLingDef | ( | ) | const |
Returns the LingDef object for which this object is created.
Definition at line 40 of file LingFeatures.cc.
Referenced by LinguisticDefinition::LingFeaturesSet::add().
const LingDef::Pos * LingFeatures::getPosDef | ( | ) | const |
Returns the pos definition for which this LingFeatures object is created.
May be NULL for global features (hmm... they aren't really global).
Definition at line 47 of file LingFeatures.cc.
Referenced by LinguisticDefinition::LingFeaturesSet::add(), LinguisticDefinition::WordPattern::LeafElement::matches(), and LinguisticDefinition::XmlLingFeaturesFormatter::output().
int LingFeatures::getReference | ( | const LingDef::Feature & | ) | const |
Definition at line 436 of file LingFeatures.cc.
int LinguisticDefinition::LingFeatures::getReference | ( | const std::string & | feature | ) | const |
Returns the value of the reference feature by the name of feature
.
If the reference feature has several values, this will return one of these in an unspecified manner. Testing of references with several values is done easily with hasReference().
void LinguisticDefinition::LingFeatures::getReferenceList | ( | const LingDef::Feature & | , | |
std::vector< int > & | ||||
) | const |
void LinguisticDefinition::LingFeatures::getReferenceList | ( | const std::string & | feature, | |
std::vector< int > & | ||||
) | const |
Returns a list containing the values for the reference feature by the name of feature
.
If the reference feature only allows one value, the list will only contain one element.
Referenced by LinguisticDefinition::XmlLingFeaturesFormatter::output().
bool LingFeatures::has | ( | const LingDef::Feature & | ) | const |
Same as has(string), except the lookup step in the parent LingDef is skipped.
Definition at line 313 of file LingFeatures.cc.
References LinguisticDefinition::LingDef::Feature::isIn().
bool LinguisticDefinition::LingFeatures::has | ( | const std::string & | feature | ) | const |
Returns wether or not the feature with the name feature
is set.
All types may be checked. If an enumeration has a value set, then the LingFields object "has" the enumeration feature as well.
Referenced by covers(), hasEnumValue(), isDefined(), main(), LinguisticDefinition::WordPattern::LeafElement::matches(), and testQuery().
int LingFeatures::hasEnumValue | ( | const LingDef::Feature & | enumValueFeature | ) | const |
Definition at line 571 of file LingFeatures.cc.
References getEnumValues(), LinguisticDefinition::LingDef::Feature::getParentEnum(), and has().
int LingFeatures::hasEnumValue | ( | const std::string & | enumValueName | ) | const |
Definition at line 558 of file LingFeatures.cc.
References LinguisticDefinition::LingDef::Pos::getFeature().
bool LingFeatures::hasNegative | ( | const LingDef::Feature & | ) | const |
Same as hasNegative(string), except the lookup step in the parent LingDef is skipped.
Definition at line 320 of file LingFeatures.cc.
bool LingFeatures::hasNegative | ( | const std::string & | feature | ) | const |
Definition at line 603 of file LingFeatures.cc.
References LinguisticDefinition::LingDef::Pos::getFeature().
Referenced by isDefined().
bool LingFeatures::hasReference | ( | const LingDef::Feature & | , | |
int | ||||
) | const |
Definition at line 460 of file LingFeatures.cc.
bool LinguisticDefinition::LingFeatures::hasReference | ( | const std::string & | feature, | |
int | referenceValue | |||
) | const |
Returns the value of the reference feature by the name of feature
is referenceValue
.
This may be used when the reference feature has several values, instead of testing the result of getReference().
If the value of the reference is unimportant, and only the existence of a value for the feature is interesting, then the general has() function may be used.
bool LingFeatures::isDefined | ( | const LingDef::Feature & | ) | const |
bool LingFeatures::isDefined | ( | const std::string & | feature | ) | const |
Definition at line 616 of file LingFeatures.cc.
References LinguisticDefinition::LingDef::Pos::getFeature().
Referenced by testQuery().
const LingFeatures & LingFeatures::operator+= | ( | const LingDef::Feature & | ) |
const LingFeatures & LingFeatures::operator+= | ( | const std::string & | ) |
const LingFeatures & LingFeatures::operator-= | ( | const LingDef::Feature & | ) |
Same as setNegative(LingDef::Feature &).
Definition at line 653 of file LingFeatures.cc.
References setNegative().
const LingFeatures & LingFeatures::operator-= | ( | const std::string & | ) |
Same as setNegative(std::string &).
Definition at line 645 of file LingFeatures.cc.
References setNegative().
void LingFeatures::set | ( | const LingDef::Feature & | ) |
Same as set(string), except the lookup step in the parent LingDef is skipped.
Definition at line 149 of file LingFeatures.cc.
void LinguisticDefinition::LingFeatures::set | ( | const std::string & | feature | ) |
Sets the feature with the name feature
.
This is valid if feature
is a feature defined for the pos for which this LingFeatures object is created, and
Referenced by execute(), operator+=(), LinguisticDefinition::XmlLingFeaturesFormatter::populateLingFeatures(), setDefaultForEnum(), setDefaults(), and setEnum().
void LingFeatures::setDefaultForEnum | ( | const LingDef::Feature & | enumFeature | ) |
Definition at line 696 of file LingFeatures.cc.
References LinguisticDefinition::LingDef::Feature::enumChildrenBegin(), LinguisticDefinition::LingDef::Feature::enumChildrenEnd(), and set().
void LingFeatures::setDefaults | ( | ) |
Definition at line 711 of file LingFeatures.cc.
References LinguisticDefinition::LingDef::Pos::defaultFeaturesBegin(), LinguisticDefinition::LingDef::Pos::defaultFeaturesEnd(), LinguisticDefinition::LingDef::Pos::getSuperPos(), and set().
Referenced by LingFeatures(), LinguisticDefinition::XmlLingFeaturesFormatter::populateLingFeatures(), and setPosDef().
void LingFeatures::setEnum | ( | const LingDef::Feature & | enumFeature, | |
const LingDef::Feature & | valueFeature | |||
) |
Definition at line 493 of file LingFeatures.cc.
References LinguisticDefinition::LingDef::Feature::getParentEnum(), and set().
void LinguisticDefinition::LingFeatures::setEnum | ( | const std::string & | enumFeature, | |
const std::string & | valueFeature | |||
) |
void LingFeatures::setForm | ( | const std::string & | ) |
Definition at line 747 of file LingFeatures.cc.
Referenced by LinguisticDefinition::XmlLingFeaturesFormatter::populateLingFeatures().
void LingFeatures::setLemma | ( | const std::string & | ) |
Definition at line 733 of file LingFeatures.cc.
Referenced by LinguisticDefinition::XmlLingFeaturesFormatter::populateLingFeatures().
void LingFeatures::setNegative | ( | const LingDef::Feature & | ) |
void LinguisticDefinition::LingFeatures::setNegative | ( | const std::string & | feature | ) |
Referenced by execute(), and operator-=().
void LingFeatures::setPosDef | ( | const LingDef::Pos & | ) |
Sets the pos definition for which this object will be defined.
This should only be done on freshly created objects, since otherwise the old features will come from another pos, which does not make any sense.
Definition at line 54 of file LingFeatures.cc.
References setDefaults().
Referenced by LinguisticDefinition::XmlLingFeaturesFormatter::populateLingFeatures().
void LingFeatures::setReference | ( | const LingDef::Feature & | , | |
int | ||||
) |
Definition at line 422 of file LingFeatures.cc.
References LinguisticDefinition::LingDef::Feature::allowSeveralValues().
void LinguisticDefinition::LingFeatures::setReference | ( | const std::string & | feature, | |
int | ||||
) |
Sets the value of the reference feature by the name of feature
.
If so defined, a reference feature may have several values. This function will then add a reference value, otherwise it will replace the existing value.
Referenced by execute(), and LinguisticDefinition::XmlLingFeaturesFormatter::populateLingFeatures().
void LingFeatures::unset | ( | const LingDef::Feature & | ) |
Same as unset(string), except the lookup step in the parent LingDef is skipped.
Definition at line 166 of file LingFeatures.cc.
void LinguisticDefinition::LingFeatures::unset | ( | const std::string & | feature | ) |
Unsets the feature with the name feature
.
All types may be unset. If an enumeration is unset, then the enumeration value will be unset.
Referenced by setNegative(), and testQuery().
friend class LingDef [friend] |
Definition at line 55 of file LingFeatures.h.