Skip to content
Open
23 changes: 19 additions & 4 deletions inflection/src/inflection/dialog/DisplayValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
namespace inflection::dialog {


DisplayValue::DisplayValue(const ::std::u16string& displayString, const ::std::map<SemanticFeature, ::std::u16string>& constraintMap)
DisplayValue::DisplayValue(
const ::std::u16string& displayString,
const ::std::map<SemanticFeature, ::std::u16string>& constraintMap
)
: super()
, displayString(displayString)
, constraintMap(constraintMap)
Expand All @@ -21,11 +24,23 @@ DisplayValue::DisplayValue(const ::std::u16string& value)
{
}

DisplayValue::DisplayValue(const SpeakableString& value, const SemanticFeature& speakFeature)
: DisplayValue(value.getPrint(), {})
DisplayValue::DisplayValue(
const SpeakableString& value,
const SemanticFeature& speakFeature
)
: DisplayValue(value, speakFeature, {})
{
}

DisplayValue::DisplayValue(
const SpeakableString& value,
const SemanticFeature& speakFeature,
const ::std::map<SemanticFeature, ::std::u16string>& constraintMap
)
: DisplayValue(value.getPrint(), constraintMap)
{
if (!value.speakEqualsPrint()) {
constraintMap.emplace(speakFeature, value.getSpeak());
this->constraintMap.emplace(speakFeature, value.getSpeak());
}
}

Expand Down
7 changes: 7 additions & 0 deletions inflection/src/inflection/dialog/DisplayValue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class INFLECTION_CLASS_API inflection::dialog::DisplayValue
* @param speakFeature The speakFeature from the SemanticFeatureModel that represents the SemanticFeature for the speak information for a SpeakableString.
*/
DisplayValue(const SpeakableString& value, const SemanticFeature& speakFeature);
/**
* Construct a display value with a SpeakableString.
* @param value A SpeakableString
* @param speakFeature The speakFeature from the SemanticFeatureModel that represents the SemanticFeature for the speak information for a SpeakableString.
* @param constraintMap The intitial constraint map.
*/
DisplayValue(const SpeakableString& value, const SemanticFeature& speakFeature, const ::std::map<SemanticFeature, ::std::u16string>& constraintMap);
/**
* The destructor
*/
Expand Down
26 changes: 25 additions & 1 deletion inflection/src/inflection/dialog/InflectableStringConcept-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
* Copyright 2021-2024 Apple Inc. All rights reserved.
*/
#include <inflection/dialog/InflectableStringConcept.h>

#include <inflection/npc.hpp>
#include <inflection/dialog/InflectableStringConcept.hpp>
#include <inflection/dialog/SemanticFeatureConcept.h>
#include <inflection/exception/ClassCastException.hpp>
#include <inflection/util/ULocale.hpp>
#include <inflection/dialog/SemanticFeature.hpp>
#include <inflection/dialog/SemanticUtils.hpp>
#include <inflection/dialog/SemanticFeatureModel.hpp>
#include <inflection/util/TypeConversionUtils.hpp>
#include <inflection/util/Validate.hpp>


INFLECTION_CAPI IDSemanticFeatureConcept* iinf_toSemanticFeatureConcept(IDInflectableStringConcept* thisObject, UErrorCode*)
{
return (IDSemanticFeatureConcept*)thisObject;
Expand Down Expand Up @@ -47,6 +51,26 @@ iinf_create(const IDSemanticFeatureModel* model, const IDSpeakableString* value,
return nullptr;
}

INFLECTION_CAPI IDInflectableStringConcept*
iinf_createWithDefaults(const IDSemanticFeatureModel* model, const IDSpeakableString* value,
const IDDisplayValue_Constraint* defaultConstraints, int32_t defaultConstraintsLen, UErrorCode* status) {
if (status != nullptr && U_SUCCESS(*status)) {
try {
auto defaultConstraintsMap(inflection::dialog::SemanticUtils::to_constraintMap(*npc((const inflection::dialog::SemanticFeatureModel*)model), defaultConstraints, defaultConstraintsLen));

return (IDInflectableStringConcept*) new ::inflection::dialog::InflectableStringConcept(
(const ::inflection::dialog::SemanticFeatureModel*)model,
*((const ::inflection::dialog::SpeakableString*)value),
defaultConstraintsMap
);
}
catch (const ::std::exception& e) {
inflection::util::TypeConversionUtils::convert(e, status);
}
}
return nullptr;
}

INFLECTION_CAPI void
iinf_destroy(IDInflectableStringConcept* thisObject)
{
Expand Down
17 changes: 15 additions & 2 deletions inflection/src/inflection/dialog/InflectableStringConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@

namespace inflection::dialog {

InflectableStringConcept::InflectableStringConcept(const SemanticFeatureModel* model, const SpeakableString& value)

InflectableStringConcept::InflectableStringConcept(
const SemanticFeatureModel* model,
const SpeakableString& value
)
: InflectableStringConcept(model, value, {})
{
}

InflectableStringConcept::InflectableStringConcept(
const SemanticFeatureModel* model,
const SpeakableString& value,
const ::std::map<SemanticFeature, ::std::u16string>& intitialConstraints
)
: super(model)
, value(value)
, defaultDisplayValue(value, *npc(super::getSpeakFeature()))
, defaultDisplayValue(value, *npc(super::getSpeakFeature()), intitialConstraints)
{
}

Expand Down
15 changes: 14 additions & 1 deletion inflection/src/inflection/dialog/InflectableStringConcept.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <inflection/dialog/SpeakableString.h>
#include <inflection/dialog/SemanticFeatureConcept.h>
#include <inflection/dialog/SemanticFeatureModel.h>

#include <inflection/dialog/SemanticUtils.hpp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This internal C++ header should not be used in public C API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix that

/**
* An object that provides a way to format a word with additional grammatical category values or semantic features of a word for a given language.
*/
Expand Down Expand Up @@ -34,6 +34,19 @@ INFLECTION_CAPI IDInflectableStringConcept* iinf_toInflectableStringConcept(IDSe
* This is set to a failure when a failure has occurred during execution.
*/
INFLECTION_CAPI IDInflectableStringConcept* iinf_create(const IDSemanticFeatureModel* model, const IDSpeakableString* value, UErrorCode* status);
/**
* Constructs a concept given a semantic feature model and a speakable string
*
* @param model - The semantic feature model required to initialize the concept.
* @param value - The speakable string to convert to a concept
* @param defaultConstraints - The initial defaultConstraints to apply to the concept
* @param defaultConstraintsLen - The number of semantic features and values provided
* @param status Must be a valid pointer to an error code value,
* which must not indicate a failure before the function call.
* This is set to a failure when a failure has occurred during execution.
*/
INFLECTION_CAPI IDInflectableStringConcept* iinf_createWithDefaults(const IDSemanticFeatureModel* model, const IDSpeakableString* value,
const IDDisplayValue_Constraint* defaultConstraints, int32_t defaultConstraintsLen, UErrorCode* status);
/**
* Destructor
*/
Expand Down
9 changes: 9 additions & 0 deletions inflection/src/inflection/dialog/InflectableStringConcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ class INFLECTION_CLASS_API inflection::dialog::InflectableStringConcept
* @param value - The speakable string to convert to a concept
*/
InflectableStringConcept(const SemanticFeatureModel* model, const SpeakableString& value);

/**
* Constructs a concept given a semantic feature model and a speakable string
*
* @param model - The semantic feature model required to initialize the concept.
* @param value - The speakable string to convert to a concept
* @param intitialConstraints - The intitial constraints for the map.
*/
InflectableStringConcept(const SemanticFeatureModel* model, const SpeakableString& value, const std::map<SemanticFeature, ::std::u16string>& intitialConstraints);
/**
* Copy constructor
*/
Expand Down
1 change: 1 addition & 0 deletions inflection/src/inflection/dialog/PronounConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ PronounConcept::PronounConcept(const SemanticFeatureModel& model, const ::std::v
if (pronounData->numValues() == 0) {
throw ::inflection::exception::IllegalArgumentException(u"Display data can not be empty.");
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this file needs to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup sure, I mistakenly added a line and forgot

for (const auto &[semanticFeature, grammeme]: defaultConstraints) {
this->defaultConstraints.emplace(semanticFeature.getName(), grammeme);
}
Expand Down
Loading