You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2023/02/24 10:03:29 UTC

[jena] branch main updated: GH-1768: Include statement-as-resource cases

This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git


The following commit(s) were added to refs/heads/main by this push:
     new 0b9837da50 GH-1768: Include statement-as-resource cases
     new dd6bf93112 Merge pull request #1769 from afs/gh1768-add-stmt
0b9837da50 is described below

commit 0b9837da50b80b5e8dffbb9420b2a4420b08dc26
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Fri Feb 24 09:01:33 2023 +0000

    GH-1768: Include statement-as-resource cases
---
 .../apache/jena/ontology/impl/OntResourceImpl.java |  2 +-
 .../apache/jena/rdf/model/impl/ResourceImpl.java   | 38 +++++++++++++++-------
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/jena-core/src/main/java/org/apache/jena/ontology/impl/OntResourceImpl.java b/jena-core/src/main/java/org/apache/jena/ontology/impl/OntResourceImpl.java
index c5be26d9b9..462f0cf3bd 100644
--- a/jena-core/src/main/java/org/apache/jena/ontology/impl/OntResourceImpl.java
+++ b/jena-core/src/main/java/org/apache/jena/ontology/impl/OntResourceImpl.java
@@ -154,7 +154,7 @@ public class OntResourceImpl
      */
     @Override
     public boolean isOntLanguageTerm() {
-        if (!isAnon()) {
+        if ( isURIResource() ) {
             for ( String KNOWN_LANGUAGE : KNOWN_LANGUAGES )
             {
                 if ( getURI().startsWith( KNOWN_LANGUAGE ) )
diff --git a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ResourceImpl.java b/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ResourceImpl.java
index 2e3da532fd..9ff4884e25 100644
--- a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ResourceImpl.java
+++ b/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ResourceImpl.java
@@ -115,8 +115,14 @@ public class ResourceImpl extends EnhNode implements Resource {
     }
 
     @Override
-    public Object visitWith( RDFVisitor rv )
-        { return isAnon() ? rv.visitBlank( this, getId() ) : rv.visitURI( this, getURI() ); }
+    public Object visitWith(RDFVisitor rv) {
+        if ( isAnon() )
+            return rv.visitBlank(this, getId());
+        if ( isStmtResource() )
+            return rv.visitStmt(this, getStmtTerm());
+        // if isURIResource()
+        return rv.visitURI(this, getURI());
+    }
 
     @Override
     public Resource asResource()
@@ -127,14 +133,18 @@ public class ResourceImpl extends EnhNode implements Resource {
         { throw new LiteralRequiredException( asNode() ); }
 
     @Override
-    public Resource inModel( Model m )
-        {
-        return
-            getModel() == m ? this
-            : isAnon() ? m.createResource( getId() )
-            : asNode().isConcrete() == false ? (Resource) m.getRDFNode( asNode() )
-            : m.createResource( getURI() );
-        }
+    public Resource inModel( Model m ) {
+        if ( getModel() == m )
+            return this;
+        if ( isAnon() )
+            return m.createResource( getId() );
+        if ( isStmtResource() )
+            return  m.createResource( getStmtTerm() );
+        if ( asNode().isConcrete() == false )
+            return (Resource) m.getRDFNode( asNode() );
+        // if isURIResource()
+        return m.createResource(getURI());
+    }
 
     private static Node fresh( String uri )
         { return uri == null ? NodeFactory.createBlankNode() : NodeFactory.createURI( uri ); }
@@ -160,12 +170,16 @@ public class ResourceImpl extends EnhNode implements Resource {
 
     @Override
     public String getNameSpace() {
-        return isAnon() ? null : node.getNameSpace();
+        if ( ! isURIResource() )
+            return null;
+        return node.getNameSpace();
     }
 
 	@Override
     public String getLocalName() {
-        return isAnon() ? null : node.getLocalName();
+	    if ( ! isURIResource() )
+	        return null;
+	    return node.getLocalName();
     }
 
     @Override