Skip to content

Commit

Permalink
dont write visibility meta triple if visibility == true (default in a…
Browse files Browse the repository at this point in the history
…ll normal datasets), use boolean value for visible and also for hasCompleteGeometry triples
  • Loading branch information
patrickbr committed Jan 9, 2025
1 parent 0a65b36 commit f40097c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 52 deletions.
5 changes: 3 additions & 2 deletions include/osm2rdf/ttl/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ inline std::string IRI__XSD_DECIMAL;
inline std::string IRI__XSD_DOUBLE;
inline std::string IRI__XSD_FLOAT;
inline std::string IRI__XSD_INTEGER;
inline std::string IRI__XSD_BOOLEAN;
inline std::string IRI__XSD_YEAR;
inline std::string IRI__XSD_YEAR_MONTH;

inline std::string LITERAL__NO;
inline std::string LITERAL__YES;
inline std::string LITERAL__FALSE;
inline std::string LITERAL__TRUE;

// Arrays holding values depending on the used dataset
const static inline std::vector<std::string> DATASET_ID = {"osm", "ohm"};
Expand Down
34 changes: 22 additions & 12 deletions src/osm/FactHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ using osm2rdf::ttl::constants::IRI__XSD_DOUBLE;
using osm2rdf::ttl::constants::IRI__XSD_INTEGER;
using osm2rdf::ttl::constants::IRI__XSD_YEAR;
using osm2rdf::ttl::constants::IRI__XSD_YEAR_MONTH;
using osm2rdf::ttl::constants::LITERAL__NO;
using osm2rdf::ttl::constants::LITERAL__YES;
using osm2rdf::ttl::constants::LITERAL__FALSE;
using osm2rdf::ttl::constants::LITERAL__TRUE;
using osm2rdf::ttl::constants::NAMESPACE__OSM2RDF;
using osm2rdf::ttl::constants::NAMESPACE__OSM2RDF_GEOM;
using osm2rdf::ttl::constants::NAMESPACE__OSM2RDF_META;
Expand Down Expand Up @@ -242,8 +242,9 @@ void osm2rdf::osm::FactHandler<W>::relation(
_writer->writeTriple(
subj,
_writer->generateIRIUnsafe(NAMESPACE__OSM2RDF, "completeGeometry"),
relation.hasCompleteGeometry() ? osm2rdf::ttl::constants::LITERAL__YES
: osm2rdf::ttl::constants::LITERAL__NO);
relation.hasCompleteGeometry()
? osm2rdf::ttl::constants::LITERAL__TRUE
: osm2rdf::ttl::constants::LITERAL__FALSE);
}
}

Expand Down Expand Up @@ -333,7 +334,7 @@ void osm2rdf::osm::FactHandler<W>::way(const osm2rdf::osm::Way& way) {

if (_config.addWayMetadata) {
_writer->writeTriple(subj, IRI__OSMWAY_IS_CLOSED,
way.closed() ? LITERAL__YES : LITERAL__NO);
way.closed() ? LITERAL__TRUE : LITERAL__FALSE);
_writer->writeLiteralTripleUnsafe(subj, IRI__OSMWAY_NODE_COUNT,
std::to_string(way.nodes().size()),
"^^" + IRI__XSD_INTEGER);
Expand Down Expand Up @@ -390,25 +391,34 @@ template <typename W>
template <typename T>
void osm2rdf::osm::FactHandler<W>::writeMeta(const std::string& subj,
const T& object) {
// avoid writing empty changeset IDs, drop entire triple
if (object.changeset() != 0) {
_writer->writeTriple(
subj, IRI__OSMMETA_CHANGESET,
_writer->generateLiteralUnsafe(std::to_string(object.changeset()),
"^^" + IRI__XSD_INTEGER));
"^^" + IRI__XSD_INTEGER));
}
if (!object.user().empty()) {
writeSecondsAsISO(subj, IRI__OSMMETA_TIMESTAMP, object.timestamp());

writeSecondsAsISO(subj, IRI__OSMMETA_TIMESTAMP, object.timestamp());

// avoid writing empty users, drop entire triple
if (!object.user().empty()) {
_writer->writeTriple(subj, IRI__OSMMETA_USER,
_writer->generateLiteral(object.user(), ""));
}

_writer->writeTriple(
subj, IRI__OSMMETA_VERSION,
_writer->generateLiteralUnsafe(std::to_string(object.version()),
"^^" + IRI__XSD_INTEGER));
"^^" + IRI__XSD_INTEGER));

_writer->writeTriple(subj, IRI__OSMMETA_VISIBLE,
object.visible() ? osm2rdf::ttl::constants::LITERAL__YES
: osm2rdf::ttl::constants::LITERAL__NO);
// only write visibility of it is false
if (!object.visible()) {
_writer->writeTriple(subj, IRI__OSMMETA_VISIBLE,
object.visible()
? osm2rdf::ttl::constants::LITERAL__TRUE
: osm2rdf::ttl::constants::LITERAL__FALSE);
}
}

// ____________________________________________________________________________
Expand Down
8 changes: 6 additions & 2 deletions src/ttl/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ osm2rdf::ttl::Writer<T>::Writer(const osm2rdf::config::Config& config,
generateIRI(osm2rdf::ttl::constants::NAMESPACE__XML_SCHEMA, "float");
osm2rdf::ttl::constants::IRI__XSD_INTEGER =
generateIRI(osm2rdf::ttl::constants::NAMESPACE__XML_SCHEMA, "integer");
osm2rdf::ttl::constants::IRI__XSD_BOOLEAN =
generateIRI(osm2rdf::ttl::constants::NAMESPACE__XML_SCHEMA, "boolean");
osm2rdf::ttl::constants::IRI__XSD_YEAR =
generateIRI(osm2rdf::ttl::constants::NAMESPACE__XML_SCHEMA, "gYear");
osm2rdf::ttl::constants::IRI__XSD_YEAR_MONTH =
generateIRI(osm2rdf::ttl::constants::NAMESPACE__XML_SCHEMA, "gYearMonth");

osm2rdf::ttl::constants::LITERAL__NO = generateLiteral("no");
osm2rdf::ttl::constants::LITERAL__YES = generateLiteral("yes");
osm2rdf::ttl::constants::LITERAL__FALSE =
generateLiteral("false", "^^" + osm2rdf::ttl::constants::IRI__XSD_BOOLEAN);
osm2rdf::ttl::constants::LITERAL__TRUE =
generateLiteral("true", "^^" + osm2rdf::ttl::constants::IRI__XSD_BOOLEAN);

// Prepare statistic variables
_numOuts = config.numThreads + 1;
Expand Down
11 changes: 1 addition & 10 deletions tests/issues/Issue24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,8 @@ TEST(Issue24, nodeHasGeometryAsGeoSPARQL) {

ASSERT_EQ(
"osmnode:42 rdf:type osm:node .\n"
"osmnode:42 osmmeta:changeset \"0\"^^xsd:integer .\n"
"osmnode:42 osmmeta:timestamp \"1970-01-01T00:00:00\"^^xsd:dateTime .\n"
"osmnode:42 osmmeta:user \"\" .\n"
"osmnode:42 osmmeta:version \"0\"^^xsd:integer .\n"
"osmnode:42 osmmeta:visible \"yes\" .\n"
"osmnode:42 osm2rdf:facts \"0\"^^xsd:integer .\n"
"osmnode:42 geo:hasGeometry osm2rdfgeom:osm_node_42 .\n"
"osm2rdfgeom:osm_node_42 geo:asWKT "
Expand Down Expand Up @@ -270,11 +267,8 @@ TEST(Issue24, relationWithGeometryHasGeometryAsGeoSPARQL) {

ASSERT_EQ(
"osmrel:42 rdf:type osm:relation .\n"
"osmrel:42 osmmeta:changeset \"0\"^^xsd:integer .\n"
"osmrel:42 osmmeta:timestamp \"1970-01-01T00:00:00\"^^xsd:dateTime .\n"
"osmrel:42 osmmeta:user \"\" .\n"
"osmrel:42 osmmeta:version \"0\"^^xsd:integer .\n"
"osmrel:42 osmmeta:visible \"yes\" .\n"
"osmrel:42 osm2rdf:facts "
"\"0\"^^xsd:integer .\nosmrel:42 osmrel:member _:0_0 .\n_:0_0 "
"osm2rdfmember:id osmnode:23 .\n_:0_0 osm2rdfmember:role \"label\" "
Expand All @@ -289,7 +283,7 @@ TEST(Issue24, relationWithGeometryHasGeometryAsGeoSPARQL) {
"osm2rdfgeom:envelope \"POLYGON((7.5 48,7.6 48,7.6 48,7.5 48,7.5 "
"48))\"^^geo:wktLiteral .\nosmrel:42 osm2rdfgeom:obb \"POLYGON((7.5 48,"
"7.5 48,7.6 48,7.6 48,7.5 48))\"^^geo:wktLiteral .\nosmrel:42 "
"osm2rdf:completeGeometry \"yes\" .\n",
"osm2rdf:completeGeometry \"true\"^^xsd:boolean .\n",
buffer.str());

// Cleanup
Expand Down Expand Up @@ -337,11 +331,8 @@ TEST(Issue24, wayHasGeometryAsGeoSPARQL) {

ASSERT_EQ(
"osmway:42 rdf:type osm:way .\n"
"osmway:42 osmmeta:changeset \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:timestamp \"1970-01-01T00:00:00\"^^xsd:dateTime .\n"
"osmway:42 osmmeta:user \"\" .\n"
"osmway:42 osmmeta:version \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:visible \"yes\" .\n"
"osmway:42 osm2rdf:facts "
"\"0\"^^xsd:integer .\nosmway:42 geo:hasGeometry osm2rdf:way_42 "
".\nosm2rdf:way_42 geo:asWKT \"LINESTRING(48 7.5,48.1 "
Expand Down
28 changes: 2 additions & 26 deletions tests/osm/FactHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,8 @@ TEST(OSM_FactHandler, node) {

ASSERT_EQ(
"osmnode:42 rdf:type osm:node .\n"
"osmnode:42 osmmeta:changeset \"0\"^^xsd:integer .\n"
"osmnode:42 osmmeta:timestamp \"1970-01-01T00:00:00\"^^xsd:dateTime .\n"
"osmnode:42 osmmeta:user \"\" .\n"
"osmnode:42 osmmeta:version \"0\"^^xsd:integer .\n"
"osmnode:42 osmmeta:visible \"yes\" .\n"
"osmnode:42 osmkey:city \"Freiburg\" .\n"
"osmnode:42 osm2rdf:facts \"1\"^^xsd:integer "
".\nosmnode:42 geo:hasGeometry osm2rdfgeom:osm_node_42 "
Expand Down Expand Up @@ -261,11 +258,8 @@ TEST(OSM_FactHandler, relation) {

ASSERT_EQ(
"osmrel:42 rdf:type osm:relation .\n"
"osmrel:42 osmmeta:changeset \"0\"^^xsd:integer .\n"
"osmrel:42 osmmeta:timestamp \"1970-01-01T00:00:00\"^^xsd:dateTime .\n"
"osmrel:42 osmmeta:user \"\" .\n"
"osmrel:42 osmmeta:version \"0\"^^xsd:integer .\n"
"osmrel:42 osmmeta:visible \"yes\" .\n"
"osmrel:42 osmkey:city \"Freiburg\" .\n"
"osmrel:42 osm2rdf:facts \"1\"^^xsd:integer .\n"
"osmrel:42 osmrel:member _:0_0 .\n"
Expand Down Expand Up @@ -447,11 +441,8 @@ TEST(OSM_FactHandler, relationWithGeometry) {

ASSERT_EQ(
"osmrel:42 rdf:type osm:relation .\n"
"osmrel:42 osmmeta:changeset \"0\"^^xsd:integer .\n"
"osmrel:42 osmmeta:timestamp \"1970-01-01T00:00:00\"^^xsd:dateTime .\n"
"osmrel:42 osmmeta:user \"\" .\n"
"osmrel:42 osmmeta:version \"0\"^^xsd:integer .\n"
"osmrel:42 osmmeta:visible \"yes\" .\n"
"osmrel:42 osmkey:city \"Freiburg\" .\n"
"osmrel:42 osm2rdf:facts \"1\"^^xsd:integer .\nosmrel:42 "
"osmrel:member _:0_0 .\n_:0_0 osm2rdfmember:id osmnode:23 .\n_:0_0 "
Expand All @@ -466,7 +457,7 @@ TEST(OSM_FactHandler, relationWithGeometry) {
"48))\"^^geo:wktLiteral .\nosmrel:42 osm2rdfgeom:envelope \"POLYGON((7.5 "
"48,7.6 48,7.6 48,7.5 48,7.5 48))\"^^geo:wktLiteral .\nosmrel:42 "
"osm2rdfgeom:obb \"POLYGON((7.5 48,7.5 48,7.6 48,7.6 48,7.5 "
"48))\"^^geo:wktLiteral .\nosmrel:42 osm2rdf:completeGeometry \"yes\" "
"48))\"^^geo:wktLiteral .\nosmrel:42 osm2rdf:completeGeometry \"true\"^^xsd:boolean "
".\n",
buffer.str());

Expand Down Expand Up @@ -516,11 +507,8 @@ TEST(OSM_FactHandler, way) {

ASSERT_EQ(
"osmway:42 rdf:type osm:way .\n"
"osmway:42 osmmeta:changeset \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:timestamp \"1970-01-01T00:00:00\"^^xsd:dateTime .\n"
"osmway:42 osmmeta:user \"\" .\n"
"osmway:42 osmmeta:version \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:visible \"yes\" .\n"
"osmway:42 osmkey:city \"Freiburg\" .\n"
"osmway:42 osm2rdf:facts \"1\"^^xsd:integer .\n"
"osmway:42 geo:hasGeometry osm2rdf:way_42 .\n"
Expand Down Expand Up @@ -582,11 +570,8 @@ TEST(OSM_FactHandler, wayAddWayNodeOrder) {

ASSERT_EQ(
"osmway:42 rdf:type osm:way .\n"
"osmway:42 osmmeta:changeset \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:timestamp \"1970-01-01T00:00:00\"^^xsd:dateTime .\n"
"osmway:42 osmmeta:user \"\" .\n"
"osmway:42 osmmeta:version \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:visible \"yes\" .\n"
"osmway:42 osmkey:city \"Freiburg\" .\n"
"osmway:42 osm2rdf:facts \"1\"^^xsd:integer .\nosmway:42 "
"osmway:node _:0_0 .\n_:0_0 osmway:node osmnode:1 .\n_:0_0 "
Expand Down Expand Up @@ -650,11 +635,8 @@ TEST(OSM_FactHandler, wayAddWayNodeSpatialMetadataShortWay) {

ASSERT_EQ(
"osmway:42 rdf:type osm:way .\n"
"osmway:42 osmmeta:changeset \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:timestamp \"1970-01-01T00:00:00\"^^xsd:dateTime .\n"
"osmway:42 osmmeta:user \"\" .\n"
"osmway:42 osmmeta:version \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:visible \"yes\" .\n"
"osmway:42 osmkey:city \"Freiburg\" .\n"
"osmway:42 osm2rdf:facts \"1\"^^xsd:integer .\nosmway:42 "
"osmway:node _:0_0 .\n_:0_0 osmway:node osmnode:1 .\n_:0_0 "
Expand Down Expand Up @@ -723,11 +705,8 @@ TEST(OSM_FactHandler, wayAddWayNodeSpatialMetadataLongerWay) {

ASSERT_EQ(
"osmway:42 rdf:type osm:way .\n"
"osmway:42 osmmeta:changeset \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:timestamp \"1970-01-01T00:00:00\"^^xsd:dateTime .\n"
"osmway:42 osmmeta:user \"\" .\n"
"osmway:42 osmmeta:version \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:visible \"yes\" .\n"
"osmway:42 osmkey:city \"Freiburg\" .\n"
"osmway:42 osm2rdf:facts \"1\"^^xsd:integer .\nosmway:42 "
"osmway:node _:0_0 .\n_:0_0 osmway:node osmnode:1 .\n_:0_0 "
Expand Down Expand Up @@ -794,11 +773,8 @@ TEST(OSM_FactHandler, wayAddWayMetaData) {

ASSERT_EQ(
"osmway:42 rdf:type osm:way .\n"
"osmway:42 osmmeta:changeset \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:timestamp \"1970-01-01T00:00:00\"^^xsd:dateTime .\n"
"osmway:42 osmmeta:user \"\" .\n"
"osmway:42 osmmeta:version \"0\"^^xsd:integer .\n"
"osmway:42 osmmeta:visible \"yes\" .\n"
"osmway:42 osmkey:city \"Freiburg\" .\n"
"osmway:42 osm2rdf:facts \"1\"^^xsd:integer .\n"
"osmway:42 geo:hasGeometry osm2rdf:way_42 .\n"
Expand All @@ -810,7 +786,7 @@ TEST(OSM_FactHandler, wayAddWayMetaData) {
"7.6,48 7.5))\"^^geo:wktLiteral .\n"
"osmway:42 osm2rdfgeom:obb \"POLYGON((48.1 7.6,48.1 7.6,48 7.5,48 "
"7.5,48.1 7.6))\"^^geo:wktLiteral .\n"
"osmway:42 osmway:is_closed \"no\" .\n"
"osmway:42 osmway:is_closed \"false\"^^xsd:boolean .\n"
"osmway:42 osmway:nodeCount \"2\"^^xsd:integer .\n"
"osmway:42 osmway:uniqueNodeCount \"2\"^^xsd:integer .\n"
"osmway:42 osm2rdf:length \"0.141421\"^^xsd:double .\n",
Expand Down

0 comments on commit f40097c

Please sign in to comment.