Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #35 from dice-group/develop
Browse files Browse the repository at this point in the history
Patch for full IRI terms
  • Loading branch information
nkaralis authored Jun 22, 2021
2 parents ca8d9bf + 651c10b commit 37ee95a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.14)
project(rdf-parser VERSION 0.13.0)
project(rdf-parser VERSION 0.13.1)
set(CMAKE_CXX_STANDARD 20)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,31 +168,31 @@ namespace Dice::rdf_parser::internal::Turtle::Actions {
s = ss.str();

state.setLiteral_string(std::move(s));// TODO: is that necessary
state.setElement(Literal(state.getLiteral_string(), std::nullopt, "xsd:boolean"));
state.setElement(Literal(state.getLiteral_string(), std::nullopt, "http://www.w3.org/2001/XMLSchema#boolean"));
}
};

template<>
struct action<Grammar::DOUBLE> {
template<typename Input, bool SparqlQuery>
static void apply(const Input &in, States::BasicState<SparqlQuery> &state) {
state.setType_tag("xsd:double");
state.setType_tag("http://www.w3.org/2001/XMLSchema#double");
}
};

template<>
struct action<Grammar::DECIMAL> {
template<typename Input, bool SparqlQuery>
static void apply(const Input &in, States::BasicState<SparqlQuery> &state) {
state.setType_tag("xsd:decimal");
state.setType_tag("http://www.w3.org/2001/XMLSchema#decimal");
}
};

template<>
struct action<Grammar::INTEGER> {
template<typename Input, bool SparqlQuery>
static void apply(const Input &in, States::BasicState<SparqlQuery> &state) {
state.setType_tag("xsd:integer");
state.setType_tag("http://www.w3.org/2001/XMLSchema#integer");
}
};

Expand Down
40 changes: 40 additions & 0 deletions tests/LiteralsTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <Dice/RDF/ParseTerm.hpp>
#include <Dice/rdf-parser/TurtleStringParser.hpp>
#include <gtest/gtest.h>


namespace Dice::tests::rdf_parser::literals_tests {
using namespace Dice::rdf_parser::internal::Turtle;
using namespace Dice::rdf;
using namespace Dice::rdf_parser::internal::Turtle::Parsers;
using namespace Dice::rdf_parser;

TEST(LiteralsTests, boolean) {
Term term = parse_term("false");
std::cout<<term.getIdentifier();
ASSERT_EQ(term.type(), Term::NodeType::Literal_);
ASSERT_EQ(term.getIdentifier(), "\"false\"^^<http://www.w3.org/2001/XMLSchema#boolean>");
}

TEST(LiteralsTests, integer) {
Term term = parse_term("-5");
std::cout<<term.getIdentifier();
ASSERT_EQ(term.type(), Term::NodeType::Literal_);
ASSERT_EQ(term.getIdentifier(), "\"-5\"^^<http://www.w3.org/2001/XMLSchema#integer>");
}

TEST(LiteralsTests, decimal) {
Term term = parse_term("-5.0");
std::cout<<term.getIdentifier();
ASSERT_EQ(term.type(), Term::NodeType::Literal_);
ASSERT_EQ(term.getIdentifier(), "\"-5.0\"^^<http://www.w3.org/2001/XMLSchema#decimal>");
}

TEST(LiteralsTests, Double) {
Term term = parse_term("4.2E9");
std::cout<<term.getIdentifier();
ASSERT_EQ(term.type(), Term::NodeType::Literal_);
ASSERT_EQ(term.getIdentifier(), "\"4.2E9\"^^<http://www.w3.org/2001/XMLSchema#double>");
}

}
6 changes: 3 additions & 3 deletions tests/TermTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ namespace Dice::tests::rdf_parser::term_tests {
Triple doubleNumber = *iterator;

// check if they are correct
ASSERT_EQ(integerNumber.object().getIdentifier(), "\"2\"^^<xsd:integer>");
ASSERT_EQ(decimalNumber.object().getIdentifier(), "\"4.002602\"^^<xsd:decimal>");
ASSERT_EQ(doubleNumber.object().getIdentifier(), "\"1.663E-4\"^^<xsd:double>");
ASSERT_EQ(integerNumber.object().getIdentifier(), "\"2\"^^<http://www.w3.org/2001/XMLSchema#integer>");
ASSERT_EQ(decimalNumber.object().getIdentifier(), "\"4.002602\"^^<http://www.w3.org/2001/XMLSchema#decimal>");
ASSERT_EQ(doubleNumber.object().getIdentifier(), "\"1.663E-4\"^^<http://www.w3.org/2001/XMLSchema#double>");
}
}// namespace Dice::tests::rdf_parser::term_tests
1 change: 1 addition & 0 deletions tests/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "TurtleOfficialNegativeTests.cpp"
#include "TurtleOfficialPositiveTests.cpp"
#include "TurtleParserFilesTests.cpp"
#include "LiteralsTest.cpp"

int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit 37ee95a

Please sign in to comment.