-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/literal classes b node #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/java/fr/inria/corese/core/next/api/base/model/AbstractBNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package fr.inria.corese.core.next.api.base.model; | ||
|
|
||
| import fr.inria.corese.core.next.api.BNode; | ||
|
|
||
| /** | ||
| * Abstract implementation of the {@link BNode} interface, providing common functionality for blank node representations. | ||
| * A blank node (BNode) https://www.w3.org/TR/rdf12-concepts/#section-blank-nodes | ||
| */ | ||
| public abstract class AbstractBNode implements BNode { | ||
|
|
||
| /** | ||
| * Returns the string value of this blank node, which is its unique identifier. | ||
| * This method is an implementation of {@link BNode#stringValue()} and simply returns the result of {@link #getID()}. | ||
| * | ||
| * @return The string value of the blank node (its unique identifier). | ||
| */ | ||
| @Override | ||
| public String stringValue() { | ||
| return getID(); | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether this blank node is equal to another object. | ||
| * Two blank nodes are considered equal if they are the same object in memory or if they have the same unique identifier (ID). | ||
| * This method is an implementation of {@link BNode#equals(Object)}. | ||
| * | ||
| * @param o The object to compare this blank node to. | ||
| * @return {@code true} if the two blank nodes are the same object or have the same unique identifier; {@code false} otherwise. | ||
| */ | ||
| @Override | ||
| public boolean equals(Object o) { | ||
| return this == o || o instanceof BNode | ||
| && getID().equals(((BNode) o).getID()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the hash code for this blank node. The hash code is based on the unique identifier of the blank node, | ||
| * using the hash code of the ID returned by {@link #getID()}. | ||
| * This method is an implementation of {@link BNode#hashCode()}. | ||
| * | ||
| * @return The hash code for this blank node. | ||
| */ | ||
| @Override | ||
| public int hashCode() { | ||
| return getID().hashCode(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a string representation of this blank node in the form "_:{ID}" where {ID} is the unique identifier of the blank node. | ||
| * | ||
| * @return A string representing this blank node, prefixed with "_:" and followed by its unique identifier. | ||
| */ | ||
| @Override | ||
| public String toString() { | ||
| return "_:" + getID(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/fr/inria/corese/core/next/impl/temp/literal/CoreseBNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package fr.inria.corese.core.next.impl.temp.literal; | ||
|
|
||
| import fr.inria.corese.core.next.api.base.model.AbstractBNode; | ||
| import fr.inria.corese.core.next.impl.exception.IncorrectOperationException; | ||
| import fr.inria.corese.core.sparql.api.IDatatype; | ||
|
|
||
| /** | ||
| * An implementation of a blank node (BNode) used by Corese. | ||
| * A blank node (BNode) represents an unnamed node in an RDF graph, typically used to represent resources that do not have a globally unique identifier (IRI). | ||
| * This class extends {@link AbstractBNode} and provides constructors for creating a BNode either from a Corese blank node object or a given string identifier. | ||
| */ | ||
| public class CoreseBNode extends AbstractBNode { | ||
| /** | ||
| * The Corese object representing the blank node in the old API. | ||
| */ | ||
| private final fr.inria.corese.core.sparql.datatype.CoreseBlankNode coreseObject; | ||
|
|
||
| /** | ||
| * The unique identifier (ID) for the blank node. | ||
| */ | ||
| private String id; | ||
|
|
||
| /** | ||
| * Constructs a {@link CoreseBNode} instance from an {@link IDatatype} Corese object. | ||
| * The Corese object should be an instance of {@link fr.inria.corese.core.sparql.datatype.CoreseBlankNode}. | ||
| * | ||
| * @param coreseObject The {@link IDatatype} Corese object representing the blank node. | ||
| * @throws IncorrectOperationException If the provided {@link IDatatype} is not a valid {@link fr.inria.corese.core.sparql.datatype.CoreseBlankNode}. | ||
| */ | ||
| public CoreseBNode(IDatatype coreseObject) { | ||
| if (coreseObject instanceof fr.inria.corese.core.sparql.datatype.CoreseBlankNode) { | ||
| this.coreseObject = ( fr.inria.corese.core.sparql.datatype.CoreseBlankNode) coreseObject; | ||
| this.id = this.coreseObject.getID(); | ||
| } | ||
| else { | ||
| throw new IncorrectOperationException("Cannot create CoreseLiteral from a non-literal Corese object"); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a {@link CoreseBNode} instance from a string identifier. | ||
| * This constructor creates a {@link fr.inria.corese.core.sparql.datatype.CoreseBlankNode} from the provided string id. | ||
| * | ||
| * @param id The unique identifier for the blank node. | ||
| */ | ||
| public CoreseBNode(String id) { | ||
| this(new fr.inria.corese.core.sparql.datatype.CoreseBlankNode(id)); | ||
| this.id = id; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the unique identifier of the blank node. | ||
| * | ||
| * @return The ID of the blank node. | ||
| */ | ||
| @Override | ||
| public String getID() { | ||
| return id; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/fr/inria/corese/core/next/impl/temp/literal/CoreseBNodeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package fr.inria.corese.core.next.impl.temp.literal; | ||
|
|
||
| import static org.junit.Assert.*; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import fr.inria.corese.core.sparql.datatype.CoreseBlankNode; | ||
|
|
||
| public class CoreseBNodeTest { | ||
|
|
||
| private static final String BNODE_ID = "bnodeCorese123"; | ||
| private static final CoreseBlankNode coreseBlankNode = new CoreseBlankNode(BNODE_ID); | ||
|
|
||
| private CoreseBNode coreseBNodeFromCoreseObject; | ||
| private CoreseBNode coreseBNodeFromStringId; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| coreseBNodeFromCoreseObject = new CoreseBNode(coreseBlankNode); | ||
| coreseBNodeFromStringId = new CoreseBNode(BNODE_ID); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructorFromString() { | ||
| // Test creating CoreseBnode for a string ID | ||
| assertNotNull(coreseBNodeFromStringId); | ||
| assertEquals(BNODE_ID, coreseBNodeFromStringId.getID()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructorFromCoreseObject() { | ||
| // Test creating CoreseBnode for a CoreseBlankNode (old API) | ||
| assertNotNull(coreseBNodeFromCoreseObject); | ||
| assertEquals(BNODE_ID, coreseBNodeFromCoreseObject.getID()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToString() { | ||
| // Test the toString method to ensure it outputs the correct representation | ||
| String expectedString = "_:" + BNODE_ID; | ||
| assertEquals(expectedString, coreseBNodeFromStringId.toString()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worry that using
java.util.concurrent.ThreadLocalRandommay cause problems when we implement multithreading. I suggest replacing the ID generation with a call ofjava.util.UUID.randomUUID().toString()