Merge remote-tracking branch 'origin/main' into pydantic-rdf

This commit is contained in:
Snowwpanda
2025-10-09 14:16:13 +02:00
2 changed files with 59 additions and 8 deletions
@@ -0,0 +1,42 @@
package ch.eth.sis.rocrate.example.doc;
import ch.eth.sis.rocrate.SchemaFacade;
import ch.eth.sis.rocrate.facade.IMetadataEntry;
import ch.eth.sis.rocrate.facade.IPropertyType;
import ch.eth.sis.rocrate.facade.IType;
import com.fasterxml.jackson.core.JsonProcessingException;
import edu.kit.datamanager.ro_crate.RoCrate;
import edu.kit.datamanager.ro_crate.reader.FolderReader;
import edu.kit.datamanager.ro_crate.reader.RoCrateReader;
import java.util.List;
public class QuickStartRead
{
public static void main(String[] args) throws JsonProcessingException
{
RoCrateReader reader = new RoCrateReader(new FolderReader());
RoCrate crate = reader.readCrate(QuickStartWrite.TMP_EXAMPLE_CRATE);
SchemaFacade schemaFacade = SchemaFacade.of(crate);
List<IType> types = schemaFacade.getTypes();
/* Writes out all types with their entries */
for (IType type : types)
{
System.out.println(type);
for (IMetadataEntry entry : schemaFacade.getEntries(type.getId()))
{
System.out.println(entry);
}
}
/* Writes out all property types */
for (IPropertyType propertyType : schemaFacade.getPropertyTypes())
{
System.out.println(propertyType);
}
}
}
@@ -1,3 +1,4 @@
package ch.eth.sis.rocrate.example.doc;
import ch.eth.sis.rocrate.SchemaFacade;
import ch.eth.sis.rocrate.facade.*;
@@ -7,14 +8,17 @@ import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class QuickStart
public class QuickStartWrite
{
private static final String PREFIX = "";
private static final String PREFIX = "Example";
private static final String SEPARATOR = ":";
public static final String TMP_EXAMPLE_CRATE = "/tmp/example-crate";
public static void main(String[] args)
{
/* Setting up an RO-Crate with the schema facade */
@@ -59,10 +63,10 @@ public class QuickStart
}
Type experimentType = new Type();
/* Building our Experiment type */
{
Type experimentType = new Type();
experimentType.setId(PREFIX + SEPARATOR + "Experiment");
{
@@ -98,36 +102,41 @@ public class QuickStart
MetadataEntry personAndreas = new MetadataEntry();
personAndreas.setId("PERSON1");
Map<String, Serializable> properties = new LinkedHashMap<>();
personAndreas.setTypes(Set.of(personType.getId()));
properties.put("givenname", "Andreas");
properties.put("lastname", "Meier");
properties.put("identifier", "https://orcid.org/0009-0002-6541-4637");
personAndreas.setProps(properties);
personAndreas.setReferences(new LinkedHashMap<>());
schemaFacade.addEntry(personAndreas);
MetadataEntry personJuan = new MetadataEntry();
personAndreas.setId("PERSON2");
personJuan.setId("PERSON2");
personJuan.setTypes(Set.of(personType.getId()));
Map<String, Serializable> properties2 = new LinkedHashMap<>();
properties2.put("givenname", "Andreas");
properties2.put("lastname", "Meier");
properties2.put("identifier", "https://orcid.org/0009-0002-6541-4637");
personAndreas.setProps(properties2);
personJuan.setProps(properties2);
personJuan.setReferences(new LinkedHashMap<>());
schemaFacade.addEntry(personJuan);
MetadataEntry experiment1 = new MetadataEntry();
experiment1.setId("EXPERIMENT1");
experiment1.setReferences(Map.of("creator", List.of(personAndreas.getId())));
experiment1.setTypes(Set.of(experimentType.getId()));
Map<String, Serializable> propertiesExperiment = new LinkedHashMap<>();
propertiesExperiment.put("name", "Example Experiment");
propertiesExperiment.put("date", "2025-09-08 08:41:50.000"); // ISO 8601
propertiesExperiment.put("date", "2025-09-08 08:41:50.000");
experiment1.setProps(propertiesExperiment);
schemaFacade.addEntry(experiment1);
}
FolderWriter folderWriter = new FolderWriter();
folderWriter.save(schemaFacade.getCrate(), "/tmp/example-crate");
folderWriter.save(schemaFacade.getCrate(), TMP_EXAMPLE_CRATE);
}
}