hartig commented on issue #3571:
URL: https://github.com/apache/jena/issues/3571#issuecomment-3521666341

   Blank nodes in CDT literals have been the biggest challenge when we worked 
on the CDT spec. The behavior that you observe in your code snippet is indeed 
the expected behavior as per the definitions in the spec:
   
   > ```java
   >     public static void main(String... args) {
   >         String x = """
   >                 PREFIX cdt:    
<http://w3id.org/awslabs/neptune/SPARQL-CDTs/>
   >                 PREFIX ex:     <http://example.org/>
   >                 ex:s ex:p "[_:b, 42]"^^cdt:List .
   >                 """;
   > 
   >         Graph g1 = RDFParser.fromString(x, Lang.TURTLE).toGraph();
   >         Node o1 = g1.find().next().getObject();
   > 
   >         Graph g2 = RDFParser.fromString(x, Lang.TURTLE).toGraph();
   >         Node o2 = g2.find().next().getObject();
   > 
   >         // Prints true
   >         System.out.println("Same term:  "+o1.sameTermAs(o2) );
   > ```
   
   I think that `true` is correct here, at least in the sense of what it means 
for [two literals to be the same 
term](https://www.w3.org/TR/rdf12-concepts/#dfn-literal-term-equality).
   
   > ```java
   >         // This case is caught by the datatype although it is an Expr 
exception.
   >         // "blank nodes in lists cannot be compared"
   >         try {
   >             System.out.print("Same value: ");
   >             System.out.println(o1.sameValueAs(o2) );
   >         } catch (ExprEvalException ex) {
   >             System.out.println("ExprEvalException: "+ex.getMessage());
   > ```
   
   Throwing an exception in this case is correct as per the CDT spec; in 
particular, the same-value comparison of two cdt:List literals is captured by 
the [list-equal 
function](https://awslabs.github.io/SPARQL-CDTs/spec/latest.html#func_list-equal)
 where Step 5.5.1 covers the case of two blank nodes as list elements.
   
   The reason why it is an `ExprEvalException` is because the exception is 
thrown in `isEqual` of `CompositeDatatypeList`, which is the method that is 
invoked for the `=` comparisons in expressions.
   
   > ```java
   >         } catch (Exception ex) {
   >             ex.printStackTrace();
   >         }
   >         // Prints false.
   >         System.out.println("LiteralValue: " 
+o1.getLiteralValue().equals(o2.getLiteralValue()));
   >     }
   > ```
   
   Returning `false` here is also in line with the CDT spec. The part of the 
spec that is relevant in this case is [Section 5.2 Importing 
Requirements](https://awslabs.github.io/SPARQL-CDTs/spec/latest.html#importing-requirements),
 which essentially says that, every time data with CDT literals is loaded, 
blank node identifiers in the lexical forms of the CDT literals work as 
identifiers only within the context of each such loading process but not across 
loading processes. For a motivation of this, see [Section 5.1 
Motivation](https://awslabs.github.io/SPARQL-CDTs/spec/latest.html#motivation). 
Given that the code above invokes the parser twice, this counts as two loading 
processes.
   
   > Can there be a way to enforce the restrictions of use?
   
   I don't understand what you are asking here. Can you please elaborate.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to