Advice on strategy

I am building an application that handles triples data. A triple is two objects linked by a semantic relationship, which are described as subject, object and predicate. In Xojo I have build classes to hold the subject and object, and also for the triple that results from linking them together.

This is all working OK. I next need to have a way to aggregate triples together into a repository. My initial approach was to simply create an array of triples. This works OK, but it doesn’t easily allow me to serialise the aggregated collection of objects. (I should mention that for the subject, object and triple classes I am using the Einhugur JSONSerializationIII tools, allowing me to save and load JSON data). So I wondered whether it might be better to create another class (TripleStore) to hold Triple objects, and that should be serializable. But I got stuck there; specifically, how to design a class that can hold a set of other classes. I thought of having a triplesArray() property, and adding a Triple to this when it is created. But I have a nagging feeling that there should be a better approach.
Basically, I want some sort of container for Triple objects where I can add and remove them, and can also serialize/deserialize this when I need to. It really is just a container; the most I’d want to do within the class is to count the number of Triples; no ordering or other processing.

Can anyone suggest a good strategic approach to this?

Anyway, if you’re still reading, thanks, and if you have any advice that would be very welcome.

Ian.

There is an error here: a triple is “3 times something”

Tripoli: tri for triple, poli for polis (city in greek)
Tripoli: capittal of Libye
Tripoli: City in Lebanon

Confirmed by macOS dictionary…

No.

A triple in RDF is a collection of three things; a subject, object and linking predicate. In RDF terms these are all entities identified by URIs. You can learn more on this here: Semantic triple - Wikipedia .
However, in my simplified model, because I am only using one simple predicate, there is no need to manage this as a class; it’s just a URI as a string. The subject and object are complex structures and thus do need to be handled as objects in a class. So my Triple class has a subject (an object of class Node) an object (also an object of class Node) and a predicate (a URI as a String).
I didn’t spell this out in the original post because I didn’t want to get bogged down in the minutiae of RDF classes. To reiterate my main interest, it is how I might approach the design of an aggregating container class for Triple objects.

Thanks,

Ian.

RDF was the word I skipped (do not read for unknow reason, sorry).

From the French description page (in the above link, replace en with fr)

Are you using Linked Data or Linked Open Data with SparQL? TripleStores are graph databases like Neo4J

Yes. The application provides an alternative to traditional front ends for graph databases like GraphDB. This is one reason that I want to be able to aggregate the Triple objects; later I want to be able to send them to GraphDB using its API, but for now I need to just be able to manage them within my application, serialise them to something that I can save, and de-serialise them from the file system when I open the application.

Ian.

Incidentally, Neo4J is not a conventional triple store based on RDF triples. Instead it is based on a property graph. The main difference between the two is that in RDF triples the predicate is just a link characterised by a URI, and in a property graph like Neo4J the predicate is able to have properties of its own.

For another type of program I serialized the array to an JSON. It worked very well and it took not much time to develop. Parsing the JSON is easy in Xojo. So I choose that approach instead of thinking about the ultimate solution. Kem Tekinay has a generic serialization solution. Maybe you want to try that: https://forum.xojo.com/t/writing-reading-object-files-to-disk/53126

Used array is 2-dim of type boolean. Write to file:

Public Sub SaveGameToFile()
  // Create JSON object
  Dim json As New JSONItem
  Dim jsonArray As New JSONItem
  
  // Converteer the 2D array to a JSON structure
  For row As Integer = 0 To CellArray1.LastRowIndex
    Dim rowArray As New JSONItem
    For col As Integer = 0 To CellArray1.LastIndex(2)
      rowArray.Append(CellArray1(row, col))
    Next
    jsonArray.Append(rowArray)
  Next
  
  // Add the array to the JSON object
  json.Value("data") = jsonArray
  
  // Save the JSON to a file
  
  
  Var file As FolderItem = FolderItem.ShowSaveFileDialog(SaveFile.JSONFileType, "Save game")
  
  If file <> Nil Then
    Try
      Dim output As TextOutputStream = TextOutputStream.Create(file)
      output.Write(json.ToString)
      output.Close
      MessageBox("Game saved as: " + file.NativePath)
    Catch e As IOException
      MessageBox("Error writing file: " + e.Message)
    End Try
  End If
End Sub

Read the file:

Public Sub ReadGameFromFile()
  // Read the JSON file
  Var file As FolderItem = FolderItem.ShowOpenFileDialog(savefile.JSONFileType)
  
  
  
  If file <> Nil And file.Exists Then
    Try
      Var Input As TextInputStream = TextInputStream.Open(file)
      var jsonString As String = Input.ReadAll
      Input.Close
      
      // Parse the jSON
      var json As New JSONItem(jsonString)
      
      // Get the array data
      var jsonArray As JSONItem = json.Value("data")
      
      // Create a new 2D array
      Var rows As Integer = jsonArray.Count - 1
      var cols As Integer = jsonArray.ChildAt(0).Count - 1
      
      
      // Fill the array with the JSON data
      For row As Integer = 0 To rows
        var rowArray As JSONItem = jsonArray.ChildAt(row)
        For col As Integer = 0 To cols
          CellArray1(row, col) = rowArray.ValueAt(col)
        Next
      Next
      PlayCanvas.Refresh
      
    Catch e As IOException
      MessageBox("Error reading file " + e.Message)
    Catch e As JSONException
      MessageBox("Error parsing JSON: " + e.Message)
    End Try
  Else
    MessageBox("File not found!")
  End If
  
  
End Sub