Skip to content

Commit

Permalink
Drop legacy (v2) internal stuff from RDFCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco De Salvo committed Oct 4, 2024
1 parent 78a4b96 commit 0f8fb19
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
1 change: 0 additions & 1 deletion RDFSharp.Test/Model/RDFCollectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public void ShouldCreateEmptyCollection(RDFModelEnums.RDFItemTypes itemType)
Assert.IsTrue(coll.ItemsCount == 0);
Assert.IsTrue(coll.ReificationSubject.Equals(RDFVocabulary.RDF.NIL));
Assert.IsTrue(coll.InternalReificationSubject.IsBlank);
Assert.IsFalse(coll.AcceptDuplicates);

int i = 0;
foreach (RDFPatternMember item in coll) i++;
Expand Down
19 changes: 6 additions & 13 deletions RDFSharp/Model/RDFCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ public int ItemsCount
public IEnumerator<RDFPatternMember> ItemsEnumerator
=> Items.GetEnumerator();

/// <summary>
/// Flag indicating that this collection exceptionally accepts duplicates
/// </summary>
internal bool AcceptDuplicates { get; set; }

/// <summary>
/// List of the items collected by the collection
/// </summary>
Expand All @@ -69,13 +64,11 @@ public IEnumerator<RDFPatternMember> ItemsEnumerator
/// Default ctor to build an empty collection of the given type
/// (initial configuration of the collection is "rdf:Nil")
/// </summary>
public RDFCollection(RDFModelEnums.RDFItemTypes itemType) : this(itemType, false) { }
internal RDFCollection(RDFModelEnums.RDFItemTypes itemType, bool acceptDuplicates)
public RDFCollection(RDFModelEnums.RDFItemTypes itemType)
{
ItemType = itemType;
ReificationSubject = RDFVocabulary.RDF.NIL;
InternalReificationSubject = new RDFResource();
AcceptDuplicates = acceptDuplicates;
Items = new List<RDFPatternMember>();
}
#endregion
Expand Down Expand Up @@ -122,7 +115,7 @@ public RDFCollection AddItem(RDFLiteral item)
/// </summary>
internal void AddItemInternal(RDFPatternMember item)
{
if (AcceptDuplicates || Items.Find(x => x.Equals(item)) == null)
if (Items.Find(x => x.Equals(item)) == null)
{
//Add item to collection
Items.Add(item);
Expand Down Expand Up @@ -189,7 +182,7 @@ public RDFGraph ReifyCollection()
int itemCount = 0;

//Collection can be reified only if it has at least one item
foreach (RDFPatternMember listEnum in this)
foreach (RDFPatternMember collectionItem in this)
{
//Count the items to keep track of the last one, which will be connected to rdf:nil
itemCount++;
Expand All @@ -198,10 +191,10 @@ public RDFGraph ReifyCollection()
reifColl.AddTriple(new RDFTriple(reifSubj, RDFVocabulary.RDF.TYPE, RDFVocabulary.RDF.LIST));

// Subject -> rdf:first -> RDFCollection.ITEM[i]
if (ItemType == RDFModelEnums.RDFItemTypes.Resource)
reifColl.AddTriple(new RDFTriple(reifSubj, RDFVocabulary.RDF.FIRST, (RDFResource)listEnum));
if (collectionItem is RDFResource collectionItemResource)
reifColl.AddTriple(new RDFTriple(reifSubj, RDFVocabulary.RDF.FIRST, collectionItemResource));
else
reifColl.AddTriple(new RDFTriple(reifSubj, RDFVocabulary.RDF.FIRST, (RDFLiteral)listEnum));
reifColl.AddTriple(new RDFTriple(reifSubj, RDFVocabulary.RDF.FIRST, (RDFLiteral)collectionItem));

//Not the last one: Subject -> rdf:rest -> NEWBLANK
if (itemCount < ItemsCount)
Expand Down

0 comments on commit 0f8fb19

Please sign in to comment.