Skip to content
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

Kinds as rdfs:subClassOf #198

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD Suppressions 1.2//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>
<!-- global suppressions -->
<suppress checks="AvoidStarImport" files="\.java" />
<!-- global suppressions -->
<suppress checks="AvoidStarImport" files="\.java" />

<!-- core suppressions -->
<suppress checks="AbbreviationAsWordInName" files="UID\.java" />
<!-- core suppressions -->
<suppress checks="AbbreviationAsWordInName" files="UID\.java" />

<!-- examples suppressions -->
<suppress checks="LineLength" files="ExampleDataObjects.java|ExampleRdl.java|ExampleAssociations.java|MagmaCoreService.java" />
<suppress checks="MethodLength" files="ExampleDataObjects.java" />
<!-- examples suppressions -->
<suppress checks="LineLength"
files="ClassServices.java|ExampleDataObjects.java|ExampleRdl.java|ExampleAssociations.java|MagmaCoreService.java" />
<suppress checks="MethodLength" files="ExampleDataObjects.java" />

<!-- hqdm-core suppressions -->
<suppress checks="MethodName" files="impl/*" />
<suppress checks="TypeName" files="Function_.java" />
<suppress checks="ConstantName" files="HQDM.java" />
<suppress checks="AbbreviationAsWordInName" files="IRI.java|HQDM.java|RDFS.java|UID.java" />
</suppressions>
<!-- hqdm-core suppressions -->
<suppress checks="MethodName" files="impl/*" />
<suppress checks="TypeName" files="Function_.java" />
<suppress checks="ConstantName" files="HQDM.java" />
<suppress checks="AbbreviationAsWordInName" files="IRI.java|HQDM.java|RDFS.java|UID.java" />
</suppressions>
12 changes: 9 additions & 3 deletions examples/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>uk.gov.gchq.magma-core</groupId>
Expand All @@ -23,10 +25,14 @@
<groupId>uk.gov.gchq.magma-core</groupId>
<artifactId>core</artifactId>
</dependency>
<dependency>
<groupId>uk.gov.gchq.magma-core</groupId>
<artifactId>hqdm-canonical</artifactId>
</dependency>
<dependency>
<groupId>uk.gov.gchq.magma-core</groupId>
<artifactId>model-extension-example</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -36,4 +42,4 @@
<artifactId>slf4j-jdk14</artifactId>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package uk.gov.gchq.magmacore.examples.kinds;

import static org.junit.Assert.assertTrue;

import java.util.UUID;

import org.junit.Test;

import uk.gov.gchq.magmacore.hqdm.model.Individual;
import uk.gov.gchq.magmacore.hqdm.model.KindOfOrganization;
import uk.gov.gchq.magmacore.hqdm.model.KindOfOrganizationComponent;
import uk.gov.gchq.magmacore.hqdm.model.Organization;
import uk.gov.gchq.magmacore.hqdm.model.PossibleWorld;
import uk.gov.gchq.magmacore.hqdm.model.Thing;
import uk.gov.gchq.magmacore.hqdm.rdf.iri.IRI;
import uk.gov.gchq.magmacore.hqdm.rdf.iri.IriBase;
import uk.gov.gchq.magmacore.hqdm.rdfbuilders.IndividualBuilder;
import uk.gov.gchq.magmacore.hqdm.rdfbuilders.KindOfOrganizationBuilder;
import uk.gov.gchq.magmacore.hqdm.rdfbuilders.KindOfOrganizationComponentBuilder;
import uk.gov.gchq.magmacore.hqdm.services.SpatioTemporalExtentServices;
import uk.gov.gchq.magmacore.service.MagmaCoreService;
import uk.gov.gchq.magmacore.service.MagmaCoreServiceFactory;

/**
* Create a KindOfOrganization and make a Thing a member_of_kind of it, then persist the Thing and
* make sure it is read back as an Organization.
*
* <p>
* This demonstrates the implementation of instances of 'kinds' as new entity types.
* </p>
*/
public class CreateOrganizationSubTypeUsingKinds {
/*
* A Base URL for the tests.
*/
private static IriBase TEST_BASE = new IriBase("test", "http://example.com/test#");

/**
* Unit test.
*/
@Test
public void test() {
// ACME Ltd will be a part of this possibleWorld.
final PossibleWorld possibleWorld = SpatioTemporalExtentServices.createPossibleWorld(randomIri());

// We need a kind of organization component for the kind of organization.
final KindOfOrganizationComponent componentKind = new KindOfOrganizationComponentBuilder(randomIri())
.build();

// Create a new kind of organization to represent companies.
// This will also make the new kind into a sub-type of organization.
final KindOfOrganization companies = new KindOfOrganizationBuilder(randomIri())
.has_Component_By_Class_M(componentKind)
.build();

// Create an Individual and make it a member_of_kind of the companies kind.
// This will also mean that the individual is of type organization, via its kind.
final Individual acmeLtd = new IndividualBuilder(randomIri())
.member_Of_Kind(companies)
.part_Of_Possible_World_M(possibleWorld)
.build();

// Persist everything.
final MagmaCoreService service = MagmaCoreServiceFactory.createWithJenaDatabase();
service.beginWrite();
service.create(companies);
service.create(acmeLtd);
service.commit();

// Read back the organization.
service.beginRead();
final Thing acmeFromDatabase = service.get(acmeLtd.getId());
service.commit();

// Confirm that the entity created as an individual is now actually an organization as well.
assertTrue(acmeFromDatabase instanceof Organization);
}

/**
* Utility method.
*
* @return IRI
*/
private static IRI randomIri() {
return new IRI(TEST_BASE, UUID.randomUUID().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import uk.gov.gchq.magmacore.hqdm.model.SpatioTemporalExtent;
import uk.gov.gchq.magmacore.hqdm.model.Thing;
import uk.gov.gchq.magmacore.hqdm.rdf.iri.IRI;
import uk.gov.gchq.magmacore.hqdm.rdf.iri.RDFS;
import uk.gov.gchq.magmacore.hqdm.services.SpatioTemporalExtentServices;

/**
Expand Down Expand Up @@ -213,6 +214,7 @@ public final AcceptanceOfOfferBuilder member_Of(
*/
public final AcceptanceOfOfferBuilder member_Of_Kind_M(final KindOfActivity kindOfActivity) {
this.acceptanceOfOffer.addValue(MEMBER_OF_KIND, kindOfActivity.getId());
this.acceptanceOfOffer.addValue(RDFS.RDF_TYPE, kindOfActivity.getId());
return this;
}

Expand Down Expand Up @@ -245,8 +247,7 @@ public final AcceptanceOfOfferBuilder part_Of_M(final AgreeContract agreeContrac
/**
* A {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} relationship type where a
* {@link uk.gov.gchq.magmacore.hqdm.model.SociallyConstructedObject} may be a
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} one or more
* {@link AgreementExecution}.
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} one or more {@link AgreementExecution}.
*
* @param agreementExecution The AgreementExecution.
* @return This builder.
Expand All @@ -258,13 +259,12 @@ public final AcceptanceOfOfferBuilder part_Of_(final AgreementExecution agreemen

/**
* A {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} relationship type where a
* {@link SpatioTemporalExtent} may be {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF}
* one or more {@link PossibleWorld}.
* {@link SpatioTemporalExtent} may be {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} one
* or more {@link PossibleWorld}.
*
* <p>
* Note: The relationship is optional because a {@link PossibleWorld} is not
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} any other
* {@link SpatioTemporalExtent}.
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} any other {@link SpatioTemporalExtent}.
* </p>
*
* @param possibleWorld The PossibleWorld.
Expand All @@ -277,8 +277,8 @@ public final AcceptanceOfOfferBuilder part_Of_Possible_World_M(final PossibleWor

/**
* A {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#REFERENCES} relationship type where an
* {@link AcceptanceOfOffer} {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#REFERENCES} exactly
* one {@link Offer} that is accepted.
* {@link AcceptanceOfOffer} {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#REFERENCES} exactly one
* {@link Offer} that is accepted.
*
* @param offer The Offer.
* @return Builder
Expand All @@ -304,16 +304,15 @@ public final AcceptanceOfOfferBuilder temporal__Part_Of(final SpatioTemporalExte
/**
* A {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} relationship type where a
* {@link uk.gov.gchq.magmacore.hqdm.model.State} may be a
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} one or more
* {@link Individual}.
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} one or more {@link Individual}.
*
* <p>
* Note: The relationship is optional because an {@link Individual} is not necessarily a
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} another {@link Individual},
* yet is a {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#MEMBER_OF}
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} another {@link Individual}, yet
* is a {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#MEMBER_OF}
* {@link uk.gov.gchq.magmacore.hqdm.model.State} as well as {@link Individual}. This applies to all
* subtypes of {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} that are between
* a {@code state_of_X} and {@code X}.
* subtypes of {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} that are between a
* {@code state_of_X} and {@code X}.
* </p>
*
* @param individual The Individual.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import uk.gov.gchq.magmacore.hqdm.model.SpatioTemporalExtent;
import uk.gov.gchq.magmacore.hqdm.model.Thing;
import uk.gov.gchq.magmacore.hqdm.rdf.iri.IRI;
import uk.gov.gchq.magmacore.hqdm.rdf.iri.RDFS;
import uk.gov.gchq.magmacore.hqdm.services.SpatioTemporalExtentServices;

/**
Expand Down Expand Up @@ -209,6 +210,7 @@ public final AcceptanceOfOfferForGoodsBuilder member_Of(
*/
public final AcceptanceOfOfferForGoodsBuilder member_Of_Kind_M(final KindOfActivity kindOfActivity) {
this.acceptanceOfOfferForGoods.addValue(MEMBER_OF_KIND, kindOfActivity.getId());
this.acceptanceOfOfferForGoods.addValue(RDFS.RDF_TYPE, kindOfActivity.getId());
return this;
}

Expand All @@ -227,9 +229,8 @@ public final AcceptanceOfOfferForGoodsBuilder part__Of(final SpatioTemporalExten

/**
* A {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} relationship type where an
* {@link AcceptanceOfOfferForGoods} is a
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} exactly one
* {@link OfferAndAcceptanceForGoods}.
* {@link AcceptanceOfOfferForGoods} is a {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF}
* exactly one {@link OfferAndAcceptanceForGoods}.
*
* @param offerAndAcceptanceForGoods The OfferAndAcceptanceForGoods.
* @return This builder.
Expand All @@ -243,8 +244,7 @@ public final AcceptanceOfOfferForGoodsBuilder part_Of_M(
/**
* A {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} relationship type where a
* {@link uk.gov.gchq.magmacore.hqdm.model.SociallyConstructedObject} may be a
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} one or more
* {@link AgreementExecution}.
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} one or more {@link AgreementExecution}.
*
* @param agreementExecution The AgreementExecution.
* @return This builder.
Expand All @@ -256,13 +256,12 @@ public final AcceptanceOfOfferForGoodsBuilder part_Of_(final AgreementExecution

/**
* A {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} relationship type where a
* {@link SpatioTemporalExtent} may be {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF}
* one or more {@link PossibleWorld}.
* {@link SpatioTemporalExtent} may be {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} one
* or more {@link PossibleWorld}.
*
* <p>
* Note: The relationship is optional because a {@link PossibleWorld} is not
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} any other
* {@link SpatioTemporalExtent}.
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} any other {@link SpatioTemporalExtent}.
* </p>
*
* @param possibleWorld The PossibleWorld.
Expand Down Expand Up @@ -301,16 +300,15 @@ public final AcceptanceOfOfferForGoodsBuilder temporal__Part_Of(final SpatioTemp
/**
* A {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} relationship type where a
* {@link uk.gov.gchq.magmacore.hqdm.model.State} may be a
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} one or more
* {@link Individual}.
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} one or more {@link Individual}.
*
* <p>
* Note: The relationship is optional because an {@link Individual} is not necessarily a
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} another {@link Individual},
* yet is a {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#MEMBER_OF}
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} another {@link Individual}, yet
* is a {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#MEMBER_OF}
* {@link uk.gov.gchq.magmacore.hqdm.model.State} as well as {@link Individual}. This applies to all
* subtypes of {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} that are between
* a {@code state_of_X} and {@code X}.
* subtypes of {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} that are between a
* {@code state_of_X} and {@code X}.
* </p>
*
* @param individual The Individual.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import uk.gov.gchq.magmacore.hqdm.model.SpatioTemporalExtent;
import uk.gov.gchq.magmacore.hqdm.model.Thing;
import uk.gov.gchq.magmacore.hqdm.rdf.iri.IRI;
import uk.gov.gchq.magmacore.hqdm.rdf.iri.RDFS;
import uk.gov.gchq.magmacore.hqdm.services.SpatioTemporalExtentServices;

/**
Expand Down Expand Up @@ -179,8 +180,8 @@ public final ActivityBuilder member__Of(final Class clazz) {

/**
* A {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#MEMBER_OF} relationship type where an
* {@link Activity} may be a {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#MEMBER_OF} one or
* more {@link ClassOfActivity}.
* {@link Activity} may be a {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#MEMBER_OF} one or more
* {@link ClassOfActivity}.
*
* @param classOfActivity The ClassOfActivity.
* @return This builder.
Expand All @@ -200,6 +201,7 @@ public final ActivityBuilder member_Of(final ClassOfActivity classOfActivity) {
*/
public final ActivityBuilder member_Of_Kind_M(final KindOfActivity kindOfActivity) {
this.activity.addValue(MEMBER_OF_KIND, kindOfActivity.getId());
this.activity.addValue(RDFS.RDF_TYPE, kindOfActivity.getId());
return this;
}

Expand Down Expand Up @@ -231,13 +233,12 @@ public final ActivityBuilder part_Of(final Activity activity) {

/**
* A {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} relationship type where a
* {@link SpatioTemporalExtent} may be {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF}
* one or more {@link PossibleWorld}.
* {@link SpatioTemporalExtent} may be {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} one
* or more {@link PossibleWorld}.
*
* <p>
* Note: The relationship is optional because a {@link PossibleWorld} is not
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} any other
* {@link SpatioTemporalExtent}.
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#PART_OF} any other {@link SpatioTemporalExtent}.
* </p>
*
* @param possibleWorld The PossibleWorld.
Expand Down Expand Up @@ -275,16 +276,15 @@ public final ActivityBuilder temporal__Part_Of(final SpatioTemporalExtent spatio
/**
* A {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} relationship type where a
* {@link uk.gov.gchq.magmacore.hqdm.model.State} may be a
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} one or more
* {@link Individual}.
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} one or more {@link Individual}.
*
* <p>
* Note: The relationship is optional because an {@link Individual} is not necessarily a
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} another {@link Individual},
* yet is a {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#MEMBER_OF}
* {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} another {@link Individual}, yet
* is a {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#MEMBER_OF}
* {@link uk.gov.gchq.magmacore.hqdm.model.State} as well as {@link Individual}. This applies to all
* subtypes of {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} that are between
* a {@code state_of_X} and {@code X}.
* subtypes of {@link uk.gov.gchq.magmacore.hqdm.rdf.iri.HQDM#TEMPORAL_PART_OF} that are between a
* {@code state_of_X} and {@code X}.
* </p>
*
* @param individual The Individual.
Expand Down
Loading
Loading