Skip to content

Commit

Permalink
proper prefixes for OSM changesets and user, also output OSM uid
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbr committed Jan 10, 2025
1 parent 2501399 commit 0dc87ed
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 9 deletions.
2 changes: 2 additions & 0 deletions include/osm2rdf/osm/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Node {
[[nodiscard]] osm2rdf::osm::generic::changeset_id_t changeset() const noexcept;
[[nodiscard]] std::time_t timestamp() const noexcept;
[[nodiscard]] std::string user() const noexcept;
[[nodiscard]] id_t uid() const noexcept;
[[nodiscard]] osm2rdf::osm::generic::version_t version() const noexcept;
[[nodiscard]] bool visible() const noexcept;
[[nodiscard]] const ::util::geo::DBox envelope() const noexcept;
Expand All @@ -51,6 +52,7 @@ class Node {
osm2rdf::osm::generic::changeset_id_t _changeset;
std::time_t _timestamp;
std::string _user;
id_t _uid;
osm2rdf::osm::generic::version_t _version;
bool _visible;
::util::geo::DPoint _geom;
Expand Down
2 changes: 2 additions & 0 deletions include/osm2rdf/osm/Relation.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Relation {
[[nodiscard]] osm2rdf::osm::generic::changeset_id_t changeset() const noexcept;
[[nodiscard]] std::time_t timestamp() const noexcept;
[[nodiscard]] std::string user() const noexcept;
[[nodiscard]] id_t uid() const noexcept;
[[nodiscard]] osm2rdf::osm::generic::version_t version() const noexcept;
[[nodiscard]] bool visible() const noexcept;
[[nodiscard]] const std::vector<osm2rdf::osm::RelationMember>& members()
Expand All @@ -65,6 +66,7 @@ class Relation {
osm2rdf::osm::generic::changeset_id_t _changeset;
std::time_t _timestamp;
std::string _user;
id_t _uid;
osm2rdf::osm::generic::version_t _version;
bool _visible;
std::vector<osm2rdf::osm::RelationMember> _members;
Expand Down
2 changes: 2 additions & 0 deletions include/osm2rdf/osm/Way.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Way {
[[nodiscard]] osm2rdf::osm::generic::changeset_id_t changeset() const noexcept;
[[nodiscard]] std::time_t timestamp() const noexcept;
[[nodiscard]] std::string user() const noexcept;
[[nodiscard]] id_t uid() const noexcept;
[[nodiscard]] osm2rdf::osm::generic::version_t version() const noexcept;
[[nodiscard]] bool visible() const noexcept;
[[nodiscard]] bool closed() const noexcept;
Expand All @@ -61,6 +62,7 @@ class Way {
osm2rdf::osm::generic::changeset_id_t _changeset;
std::time_t _timestamp;
std::string _user;
id_t _uid;
osm2rdf::osm::generic::version_t _version;
bool _visible;
std::vector<osm2rdf::osm::Node> _nodes;
Expand Down
11 changes: 11 additions & 0 deletions include/osm2rdf/ttl/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ const static inline std::string NAMESPACE__GEOSPARQL = "geo";
const static inline std::string NAMESPACE__OHM_NODE = "ohmnode";
const static inline std::string NAMESPACE__OHM_RELATION = "ohmrel";
const static inline std::string NAMESPACE__OHM_WAY = "ohmway";
const static inline std::string NAMESPACE__OHM_USER = "ohmuser";
const static inline std::string NAMESPACE__OHM_CHANGESET = "ohmchangeset";
const static inline std::string NAMESPACE__OHM = "ohm";
const static inline std::string NAMESPACE__OPENGIS = "ogc";
const static inline std::string NAMESPACE__OSM_NODE = "osmnode";
const static inline std::string NAMESPACE__OSM_RELATION = "osmrel";
const static inline std::string NAMESPACE__OSM_TAG = "osmkey";
const static inline std::string NAMESPACE__OSM_WAY = "osmway";
const static inline std::string NAMESPACE__OSM_USER = "osmuser";
const static inline std::string NAMESPACE__OSM_CHANGESET = "osmchangeset";
const static inline std::string NAMESPACE__OSM_META = "osmmeta";
const static inline std::string NAMESPACE__OSM = "osm";
const static inline std::string NAMESPACE__OSM2RDF = "osm2rdf";
Expand Down Expand Up @@ -74,6 +78,7 @@ inline std::string IRI__OSMMETA_CHANGESET;
inline std::string IRI__OSM2RDF__LENGTH;
inline std::string IRI__OSMMETA_TIMESTAMP;
inline std::string IRI__OSMMETA_USER;
inline std::string IRI__OSMMETA_UID;
inline std::string IRI__OSMMETA_VERSION;
inline std::string IRI__OSMMETA_VISIBLE;
inline std::string IRI__OSMWAY_IS_CLOSED;
Expand All @@ -87,6 +92,8 @@ inline std::string IRI__OSM_NODE;
inline std::string IRI__OSM_RELATION;
inline std::string IRI__OSM_TAG;
inline std::string IRI__OSM_WAY;
inline std::string IRI__OSM_USER;
inline std::string IRI__OSM_CHANGESET;

inline std::string IRI__RDF_TYPE;

Expand All @@ -111,6 +118,10 @@ const static inline std::vector<std::string> RELATION_NAMESPACE = {
NAMESPACE__OSM_RELATION, NAMESPACE__OHM_RELATION};
const static inline std::vector<std::string> WAY_NAMESPACE = {
NAMESPACE__OSM_WAY, NAMESPACE__OHM_WAY};
const static inline std::vector<std::string> CHANGESET_NAMESPACE = {
NAMESPACE__OSM_CHANGESET, NAMESPACE__OHM_CHANGESET};
const static inline std::vector<std::string> USER_NAMESPACE = {
NAMESPACE__OSM_USER, NAMESPACE__OHM_USER};

} // namespace osm2rdf::ttl::constants

Expand Down
22 changes: 18 additions & 4 deletions src/osm/FactHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

using osm2rdf::osm::constants::AREA_PRECISION;
using osm2rdf::osm::constants::BASE_SIMPLIFICATION_FACTOR;
using osm2rdf::ttl::constants::CHANGESET_NAMESPACE;
using osm2rdf::ttl::constants::DATASET_ID;
using osm2rdf::ttl::constants::IRI__GEOSPARQL__AS_WKT;
using osm2rdf::ttl::constants::IRI__GEOSPARQL__HAS_CENTROID;
Expand All @@ -46,12 +47,15 @@ using osm2rdf::ttl::constants::IRI__OSM2RDF_GEOM__OBB;
using osm2rdf::ttl::constants::IRI__OSM2RDF_MEMBER__ID;
using osm2rdf::ttl::constants::IRI__OSM2RDF_MEMBER__POS;
using osm2rdf::ttl::constants::IRI__OSM2RDF_MEMBER__ROLE;
using osm2rdf::ttl::constants::IRI__OSM_CHANGESET;
using osm2rdf::ttl::constants::IRI__OSM_NODE;
using osm2rdf::ttl::constants::IRI__OSM_RELATION;
using osm2rdf::ttl::constants::IRI__OSM_TAG;
using osm2rdf::ttl::constants::IRI__OSM_USER;
using osm2rdf::ttl::constants::IRI__OSM_WAY;
using osm2rdf::ttl::constants::IRI__OSMMETA_CHANGESET;
using osm2rdf::ttl::constants::IRI__OSMMETA_TIMESTAMP;
using osm2rdf::ttl::constants::IRI__OSMMETA_UID;
using osm2rdf::ttl::constants::IRI__OSMMETA_USER;
using osm2rdf::ttl::constants::IRI__OSMMETA_VERSION;
using osm2rdf::ttl::constants::IRI__OSMMETA_VISIBLE;
Expand Down Expand Up @@ -82,6 +86,7 @@ using osm2rdf::ttl::constants::NAMESPACE__OSM_WAY;
using osm2rdf::ttl::constants::NAMESPACE__WIKIDATA_ENTITY;
using osm2rdf::ttl::constants::NODE_NAMESPACE;
using osm2rdf::ttl::constants::RELATION_NAMESPACE;
using osm2rdf::ttl::constants::USER_NAMESPACE;
using osm2rdf::ttl::constants::WAY_NAMESPACE;

// ____________________________________________________________________________
Expand Down Expand Up @@ -397,16 +402,25 @@ void osm2rdf::osm::FactHandler<W>::writeMeta(const std::string& subj,
if (object.changeset() != 0) {
_writer->writeTriple(
subj, IRI__OSMMETA_CHANGESET,
_writer->generateLiteralUnsafe(std::to_string(object.changeset()),
"^^" + IRI__XSD_INTEGER));
_writer->generateIRI(CHANGESET_NAMESPACE[_config.sourceDataset],
object.changeset()));
}

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_USER,
_writer->generateIRI(USER_NAMESPACE[_config.sourceDataset],
object.user()));
}

// avoid writing empty user IDs, drop entire triple
if (object.uid() != 0) {
_writer->writeTriple(subj, IRI__OSMMETA_UID,
_writer->generateLiteral(std::to_string(object.uid()),
"^^" + IRI__XSD_INTEGER));
}

_writer->writeTriple(
Expand Down
7 changes: 6 additions & 1 deletion src/osm/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// along with osm2rdf. If not, see <https://www.gnu.org/licenses/>.

#include "osm2rdf/osm/Node.h"

#include "osm2rdf/osm/TagList.h"
#include "osmium/osm/node.hpp"
#include "osmium/osm/node_ref.hpp"
Expand All @@ -34,6 +33,7 @@ osm2rdf::osm::Node::Node(const osmium::Node& node) {
_timestamp = node.timestamp().seconds_since_epoch();
_changeset = node.changeset();
_user = node.user();
_uid = node.uid();
_version = node.version();
_visible = node.visible();
const auto& loc = node.location();
Expand Down Expand Up @@ -65,6 +65,11 @@ std::time_t osm2rdf::osm::Node::timestamp() const noexcept {
// ____________________________________________________________________________
std::string osm2rdf::osm::Node::user() const noexcept { return _user; }

// ____________________________________________________________________________
osm2rdf::osm::Node::id_t osm2rdf::osm::Node::uid() const noexcept {
return _uid;
}

// ____________________________________________________________________________
osm2rdf::osm::generic::version_t osm2rdf::osm::Node::version() const noexcept {
return _version;
Expand Down
4 changes: 4 additions & 0 deletions src/osm/Relation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ osm2rdf::osm::Relation::Relation(const osmium::Relation& relation) {
_timestamp = relation.timestamp().seconds_since_epoch();
_changeset = relation.changeset();
_user = relation.user();
_uid = relation.uid();
_version = relation.version();
_visible = relation.visible();
_tags = std::move(osm2rdf::osm::convertTagList(relation.tags()));
Expand Down Expand Up @@ -71,6 +72,9 @@ std::time_t osm2rdf::osm::Relation::timestamp() const noexcept {
// ____________________________________________________________________________
std::string osm2rdf::osm::Relation::user() const noexcept { return _user; }

// ____________________________________________________________________________
id_t osm2rdf::osm::Relation::uid() const noexcept { return _uid; }

// ____________________________________________________________________________
osm2rdf::osm::generic::version_t osm2rdf::osm::Relation::version()
const noexcept {
Expand Down
4 changes: 4 additions & 0 deletions src/osm/Way.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ osm2rdf::osm::Way::Way(const osmium::Way& way) {
_timestamp = way.timestamp().seconds_since_epoch();
_changeset = way.changeset();
_user = way.user();
_uid = way.uid();
_version = way.version();
_visible = way.visible();
_tags = std::move(osm2rdf::osm::convertTagList(way.tags()));
Expand Down Expand Up @@ -95,6 +96,9 @@ std::time_t osm2rdf::osm::Way::timestamp() const noexcept { return _timestamp; }
// ____________________________________________________________________________
std::string osm2rdf::osm::Way::user() const noexcept { return _user; }

// ____________________________________________________________________________
id_t osm2rdf::osm::Way::uid() const noexcept { return _uid; }

// ____________________________________________________________________________
osm2rdf::osm::generic::version_t osm2rdf::osm::Way::version() const noexcept {
return _version;
Expand Down
10 changes: 10 additions & 0 deletions src/ttl/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ osm2rdf::ttl::Writer<T>::Writer(const osm2rdf::config::Config& config,
"https://www.openstreetmap.org/relation/"},
{osm2rdf::ttl::constants::NAMESPACE__OSM_WAY,
"https://www.openstreetmap.org/way/"},
{osm2rdf::ttl::constants::NAMESPACE__OSM_USER,
"https://www.openstreetmap.org/user/"},
{osm2rdf::ttl::constants::NAMESPACE__OSM_CHANGESET,
"https://www.openstreetmap.org/changeset/"},
// ohm prefixes
{osm2rdf::ttl::constants::NAMESPACE__OHM,
"https://www.openhistoricalmap.org/"},
Expand Down Expand Up @@ -141,6 +145,8 @@ osm2rdf::ttl::Writer<T>::Writer(const osm2rdf::config::Config& config,
generateIRI(osm2rdf::ttl::constants::NAMESPACE__OSM_META, "timestamp");
osm2rdf::ttl::constants::IRI__OSMMETA_USER =
generateIRI(osm2rdf::ttl::constants::NAMESPACE__OSM_META, "user");
osm2rdf::ttl::constants::IRI__OSMMETA_UID =
generateIRI(osm2rdf::ttl::constants::NAMESPACE__OSM_META, "uid");
osm2rdf::ttl::constants::IRI__OSMMETA_VERSION =
generateIRI(osm2rdf::ttl::constants::NAMESPACE__OSM_META, "version");
osm2rdf::ttl::constants::IRI__OSMMETA_VISIBLE =
Expand All @@ -159,6 +165,10 @@ osm2rdf::ttl::Writer<T>::Writer(const osm2rdf::config::Config& config,
osm2rdf::ttl::constants::NAMESPACE__OSM_WAY, "uniqueNodeCount");
osm2rdf::ttl::constants::IRI__OSM_NODE =
generateIRI(osm2rdf::ttl::constants::NAMESPACE__OSM, "node");
osm2rdf::ttl::constants::IRI__OSM_USER =
generateIRI(osm2rdf::ttl::constants::NAMESPACE__OSM, "user");
osm2rdf::ttl::constants::IRI__OSM_CHANGESET =
generateIRI(osm2rdf::ttl::constants::NAMESPACE__OSM, "changeset");
osm2rdf::ttl::constants::IRI__OSM_RELATION =
generateIRI(osm2rdf::ttl::constants::NAMESPACE__OSM, "relation");
osm2rdf::ttl::constants::IRI__OSM_TAG =
Expand Down
8 changes: 4 additions & 4 deletions tests/ttl/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,8 @@ TEST(TTL_WriterTTL, writeStatisticJson) {
statsBuffer << statsIFStream.rdbuf();

ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"blankNodes\": 3"));
ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"header\": 20"));
ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"lines\": 25"));
ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"header\": 22"));
ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"lines\": 27"));
ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"triples\": 5"));

// Cleanup
Expand Down Expand Up @@ -766,8 +766,8 @@ TEST(TTL_WriterQLEVER, writeStatisticJson) {
statsBuffer << statsIFStream.rdbuf();

ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"blankNodes\": 3"));
ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"header\": 20"));
ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"lines\": 25"));
ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"header\": 22"));
ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"lines\": 27"));
ASSERT_THAT(statsBuffer.str(), ::testing::HasSubstr("\"triples\": 5"));

// Cleanup
Expand Down

0 comments on commit 0dc87ed

Please sign in to comment.