Skip to content

Conversation

@FrankYFTang
Copy link
Collaborator

@FrankYFTang FrankYFTang commented May 6, 2025

Address #117

Add one header file with two functions to create
icu::message2::FormatFactory and
icu::message2::SelectorFactory

Also add unit test and data driven unit test
Test data based on
inflection/test/resources/inflection/dialog/inflection/*.xml

Test formatter while the is not empty
Test Selector while the is empty, and there are one attribute
which is not "exists".

FrankYFTang added a commit to FrankYFTang/millefiori that referenced this pull request May 6, 2025
@FrankYFTang FrankYFTang requested a review from nciric May 6, 2025 23:05
@FrankYFTang
Copy link
Collaborator Author

ok, the build problem with the ubuntu build breakage is because it is using 74.2, which does not have MF2 api

libicu-dev is already the newest version (74.2-1ubuntu3.1).

@FrankYFTang FrankYFTang changed the title Add Factory for MF2 Add Factory for MF2 ( issues/117 ) May 27, 2025
@FrankYFTang
Copy link
Collaborator Author

Per inflection WG meeting 2025-05-27 Frank will remove the TEST_CASE("MF2Factory#testFormaterFromDataDriven")
and rewrite a separate data driven test in another PR

Copy link
Member

@grhoten grhoten left a comment

Choose a reason for hiding this comment

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

Is there a way to use just the C API from ICU? This library has gone through extensive effort to avoid the C++ API since the C++ ABI is not stable, which is why the ULocale class exists and the icu4cxx wrappers exist. This library is not integrated into ICU yet. Some people still have trouble deciding between using libstdc++ or libc++ in large diverse environments.

I recognize that the MF C API may not exist yet. So that may be an impossible request at this time.

Comment on lines +48 to +51
icu::message2::FormatterFactory* MF2Factory::CreateFormatterFactory() {
return new InflectionFormatterFactory();
}

icu::message2::SelectorFactory* MF2Factory::CreateSelectorFactory() {
return new InflectionSelectorFactory();
}
Copy link
Member

Choose a reason for hiding this comment

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

After thinking about this in more detail, what is the value in these factory methods? It's not caching the factory. There are no complicated data structures. The caller has to delete the factory classes.

Should InflectionFormatterFactory and InflectionSelectorFactory be exposed and allow people to stack allocate them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The value is to hide unnecessary details of which exact concrete class implement the FormatterFactory and SelectorFactory so we do not need to expose unnecessary class.

Should InflectionFormatterFactory and InflectionSelectorFactory be exposed and allow people to stack allocate them?

No, because they need to passed into
MFFunctionRegistry::Builder::adoptFormatter and adoptSelector and own by the Builder. Notice in the test code, no code free them. The code free them is inside MFFunctionRegistry::Builder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I went to ICU TC and ask them about C API (Richard is also there). The answer is currently they are waiting for the C++ and Java API to be proven stable first. Then they will consider adding a C API later.

Also add unit test and data driven unit test
Test data based on
inflection/test/resources/inflection/dialog/inflection/*.xml

Test formatter while the <result> is not empty
Test Selector while the <result> is empty, and there are one attribute
which is not "exists".

Uppercase the factory function

Change copyright, remove iostream, add comments

Fix build issue if the icu is < 77

Remove Data Driven test

Fix Locale building

Remove version Check
@FrankYFTang FrankYFTang requested a review from grhoten June 2, 2025 23:19
@FrankYFTang
Copy link
Collaborator Author

PTAL. I address all the review comments. Working on another PR for the data driven test now.

@FrankYFTang
Copy link
Collaborator Author

@grhoten Are you ok with this PR?

@FrankYFTang FrankYFTang merged commit 081f8bc into unicode-org:main Jun 4, 2025
3 checks passed
@FrankYFTang FrankYFTang deleted the AddMF2Factory branch June 4, 2025 23:13
deonajulary06 pushed a commit that referenced this pull request Aug 21, 2025
* Add Factory for MF2

Also add unit test and data driven unit test
Test data based on
inflection/test/resources/inflection/dialog/inflection/*.xml

Test formatter while the <result> is not empty
Test Selector while the <result> is empty, and there are one attribute
which is not "exists".

Uppercase the factory function

Change copyright, remove iostream, add comments

Fix build issue if the icu is < 77

Remove Data Driven test

Fix Locale building

Remove version Check

* Reformat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants