From 2c08cff67bfdb8fca984e022708806a658325a66 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 3 Oct 2024 10:30:36 +0200 Subject: [PATCH] Make sure $ chars in TTL are only enclosed in not shortened postfixes" --- src/serializers/TtlWktSerializer.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/serializers/TtlWktSerializer.cpp b/src/serializers/TtlWktSerializer.cpp index f85578e0fe..5fa3e0f330 100644 --- a/src/serializers/TtlWktSerializer.cpp +++ b/src/serializers/TtlWktSerializer.cpp @@ -237,20 +237,32 @@ void TtlWktSerializer::writeHeader() void TtlWktSerializer::write(const IfcGeom::TriangulationElement* o) { - auto ttl_object_id = [&]() { - return boost::replace_all_copy(object_id(o), "-", "_"); + auto ttl_object_id = [&](const char* const postfix = nullptr) { + using namespace ifcopenshell::geometry::settings; + auto oid = boost::replace_all_copy(object_id(o), "-", "_"); + if (oid.find('$') == std::string::npos) { + return "base:" + oid + (postfix ? postfix : (const char* const)""); + } else { + std::string base; + if (settings_.get().has()) { + base = settings_.get().get(); + } else { + base = "http://example.org/"; + } + return "<" + base + oid + (postfix ? postfix : (const char* const) "") + ">"; + } }; - filename_.stream << "base:" << ttl_object_id() << " a geo:Feature ;\n"; + filename_.stream << ttl_object_id() << " a geo:Feature ;\n"; filename_.stream << " dcterms:identifier " << escape_for_turtle( IfcUtil::convert_utf8_to_utf32(o->guid())) << " ;\n"; filename_.stream << " rdfs:label " << escape_for_turtle( IfcUtil::convert_utf8_to_utf32(o->name()) ) << " ;\n"; - filename_.stream << " geo:hasGeometry base:" << ttl_object_id() << "_geometry .\n\n"; + filename_.stream << " geo:hasGeometry " << ttl_object_id("_geometry") << " .\n\n"; if (!o->geometry().polyhedral_faces_with_holes().empty()) { - filename_.stream << "base:" << ttl_object_id() << "_geometry a geo:Geometry ;\n"; + filename_.stream << ttl_object_id("_geometry") << " a geo:Geometry ;\n"; filename_.stream << " geo:asWKT " << escape_for_turtle( IfcUtil::convert_utf8_to_utf32( capture_output( @@ -291,8 +303,8 @@ void TtlWktSerializer::write(const IfcGeom::TriangulationElement* o) } if (lowest_face) { - filename_.stream << "base:" << ttl_object_id() << " geo:hasGeometry base:" << ttl_object_id() << "_footprint_geometry .\n\n"; - filename_.stream << "base:" << ttl_object_id() << "_footprint_geometry a geo:Geometry ;\n"; + filename_.stream << ttl_object_id() << " geo:hasGeometry " << ttl_object_id("_footprint_geometry") << " .\n\n"; + filename_.stream << ttl_object_id("_footprint_geometry") << " a geo:Geometry ;\n"; filename_.stream << " geo:asWKT " << escape_for_turtle( IfcUtil::convert_utf8_to_utf32( capture_output( @@ -306,7 +318,7 @@ void TtlWktSerializer::write(const IfcGeom::TriangulationElement* o) ) << "^^geo:wktLiteral .\n\n"; } } else { - filename_.stream << "base:" << ttl_object_id() << "_geometry a geo:Geometry ;\n"; + filename_.stream << ttl_object_id("_geometry") << " a geo:Geometry ;\n"; bool force_2d = true; double z_value; for (size_t i = 2; i < o->geometry().verts().size(); i += 3) {