diff --git a/include/osm2rdf/ttl/Constants.h b/include/osm2rdf/ttl/Constants.h index 0ea7cc0..f3a8c3d 100644 --- a/include/osm2rdf/ttl/Constants.h +++ b/include/osm2rdf/ttl/Constants.h @@ -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 DATASET_ID = {"osm", "ohm"}; diff --git a/src/osm/FactHandler.cpp b/src/osm/FactHandler.cpp index 410b404..4a43d67 100644 --- a/src/osm/FactHandler.cpp +++ b/src/osm/FactHandler.cpp @@ -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; @@ -242,8 +242,9 @@ void osm2rdf::osm::FactHandler::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); } } @@ -333,7 +334,7 @@ void osm2rdf::osm::FactHandler::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); @@ -390,25 +391,34 @@ template template void osm2rdf::osm::FactHandler::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); + } } // ____________________________________________________________________________ diff --git a/src/ttl/Writer.cpp b/src/ttl/Writer.cpp index 656a8b8..54ea2b9 100644 --- a/src/ttl/Writer.cpp +++ b/src/ttl/Writer.cpp @@ -182,13 +182,17 @@ osm2rdf::ttl::Writer::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; diff --git a/tests/issues/Issue24.cpp b/tests/issues/Issue24.cpp index 50e1b4e..a590702 100644 --- a/tests/issues/Issue24.cpp +++ b/tests/issues/Issue24.cpp @@ -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 " @@ -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\" " @@ -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 @@ -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 " diff --git a/tests/osm/FactHandler.cpp b/tests/osm/FactHandler.cpp index 939ac89..44931e4 100644 --- a/tests/osm/FactHandler.cpp +++ b/tests/osm/FactHandler.cpp @@ -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 " @@ -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" @@ -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 " @@ -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()); @@ -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" @@ -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 " @@ -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 " @@ -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 " @@ -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" @@ -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",