R: Change check-constituenta to use string representation of CstType

This commit is contained in:
Ivan 2024-09-22 19:47:55 +03:00
parent c8578447f3
commit 6860706e7a
8 changed files with 24 additions and 14 deletions

View File

@ -25,7 +25,7 @@ public:
[[nodiscard]] std::string ToMinimalJSON() const;
[[nodiscard]] std::string CheckExpression(const std::string& text, rslang::Syntax syntaxHint = rslang::Syntax::UNDEF) const;
[[nodiscard]] std::string CheckConstituenta(const std::string& alias, const std::string& definition, semantic::CstType targetType) const;
[[nodiscard]] std::string CheckConstituenta(const std::string& alias, const std::string& definition, const std::string& targetType) const;
};

View File

@ -71,12 +71,11 @@ std::string RSFormJA::ToMinimalJSON() const {
}
std::string RSFormJA::CheckExpression(const std::string& text, const rslang::Syntax syntaxHint) const {
JSON result{};
auto analyser = schema->Core().RSLang().MakeAuditor();
const auto typeOK = analyser->CheckExpression(text, syntaxHint);
const auto valueOK = typeOK && analyser->CheckValue();
JSON result{};
result["parseResult"] = typeOK;
result["syntax"] = analyser->GetSyntax();
result["prefixLen"] = 0;
@ -111,14 +110,16 @@ std::string RSFormJA::CheckExpression(const std::string& text, const rslang::Syn
std::string RSFormJA::CheckConstituenta(
const std::string& alias,
const std::string& definition,
semantic::CstType targetType
const std::string& targetType
) const {
JSON result{};
JSON jType = targetType;
const auto type = jType.template get<semantic::CstType>();
auto analyser = schema->Core().RSLang().MakeAuditor();
const auto typeOK = analyser->CheckConstituenta(alias, definition, targetType);
const auto typeOK = analyser->CheckConstituenta(alias, definition, type);
const auto valueOK = typeOK && analyser->CheckValue();
JSON result{};
result["parseResult"] = typeOK;
result["syntax"] = analyser->GetSyntax();
result["prefixLen"] = analyser->prefixLen;

View File

@ -135,7 +135,7 @@ TEST_F(UTRSFormJA, CheckExpression) {
TEST_F(UTRSFormJA, CheckConstituenta) {
auto wrapper = RSFormJA::FromData(SetupSchema());
auto reponse = JSON::parse(wrapper.CheckConstituenta("A100", "X1=X1", CstType::axiom));
auto reponse = JSON::parse(wrapper.CheckConstituenta("A100", "X1=X1", "axiom"));
EXPECT_EQ(reponse.at("parseResult").get<bool>(), true);
EXPECT_EQ(reponse.at("prefixLen"), 7);
EXPECT_EQ(reponse.at("syntax"), "math");

View File

@ -19,10 +19,16 @@ Here we write upgrading notes. Make them as straightforward as possible.
### Fixed
## [0.1.7] - 2024-09-22
## [0.1.8] - 2024-09-22
### Fixed
- Change check-constituenta to use string representation of CstType
## [0.1.7] - 2024-09-22
### Added
- Improve error messages for invalid types
- Add API for checking constituenta expressions

View File

@ -1 +1 @@
0.1.7
0.1.8

View File

@ -19,7 +19,7 @@ std::string CheckConstituenta(
const std::string& jSchema,
const std::string& alias,
const std::string& expression,
int cstType
const std::string& cstType
);
PYBIND11_MODULE(pyconcept, m) {

View File

@ -40,8 +40,8 @@ std::string CheckConstituenta(
const std::string& jSchema,
const std::string& alias,
const std::string& expression,
int cstType
const std::string& cstType
) {
auto schema = RSFormJA::FromJSON(jSchema);
return schema.CheckConstituenta(alias, expression, static_cast<ccl::semantic::CstType>(cstType));
return schema.CheckConstituenta(alias, expression, cstType);
}

View File

@ -59,12 +59,15 @@ class TestBinding(unittest.TestCase):
def test_check_constituenta(self):
''' Test checking expression against given schema '''
schema = self._get_default_schema()
out1 = json.loads(pc.check_constituenta(schema, 'A100', 'X1=X1', 5))
out1 = json.loads(pc.check_constituenta(schema, 'A100', 'X1=X1', 'axiom'))
self.assertEqual(out1['parseResult'], True)
out2 = json.loads(pc.check_constituenta(schema, 'A100', 'X1=X2', 5))
out2 = json.loads(pc.check_constituenta(schema, 'A100', 'X1=X2', 'axiom'))
self.assertEqual(out2['parseResult'], False)
out3 = json.loads(pc.check_constituenta(schema, 'D100', 'X1=X1', 'term'))
self.assertEqual(out3['parseResult'], False)
def test_reset_aliases(self):
''' Test reset aliases in schema '''
schema = self._get_default_schema()