Skip to content

Commit

Permalink
Add PointInTime to MagmaCoreService.findAssociated()
Browse files Browse the repository at this point in the history
  • Loading branch information
twalmsley authored and GCHQDeveloper42 committed Jan 13, 2023
1 parent 0b6557a commit 86af1d8
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,34 @@ public List<? extends Thing> findAssociated(final IRI item, final IRI kindOfAsso

}

/**
* Find the items associated to an item by an association of a specified kind that are valid at a PointInTime.
*
* @param item IRI
* @param kindOfAssociation IRI
* @param pointInTime {@link PointInTime}
* @return {@link List} of {@link Thing}
*/
public List<? extends Thing> findAssociated(final IRI item, final IRI kindOfAssociation, final PointInTime pointInTime) {

final Set<Object> pointInTimeValues = pointInTime.value(HQDM.ENTITY_NAME);
if (pointInTimeValues == null || pointInTimeValues.isEmpty()) {
return List.of();
}

final Instant when = Instant.parse(pointInTimeValues.iterator().next().toString());

final QueryResultList queryResultList = database
.executeQuery(String.format(MagmaCoreServiceQueries.FIND_ASSOCIATED,
kindOfAssociation, item, item,
kindOfAssociation, item, item,
kindOfAssociation, item, item));

final QueryResultList queryResults = filterByPointInTime(when, queryResultList);
return database.toTopObjects(queryResults);

}

/**
* A case-sensitive search for entities in a specified class with a sign containing the given text.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,66 +362,92 @@ public class MagmaCoreServiceQueries {
""";

/**
* TODO: Comment.
* Find things associated to a given thing by an association of a given kind.
*/
public static final String FIND_ASSOCIATED = """
PREFIX hqdm: <http://www.semanticweb.org/hqdm#>
select ?s ?p ?o
select ?s ?p ?o ?start ?finish
where
{
{
select distinct ?s ?p ?o
WHERE {
BIND(<%s> as ?kind_of_association)
?from hqdm:temporal_part_of <%s>;
hqdm:participant_in ?association.
?association hqdm:member_of_kind ?kind_of_association.
?participant hqdm:participant_in ?association;
hqdm:temporal_part_of ?s.
?s ?p ?o.
FILTER(?s != <%s>)
}
select distinct ?s ?p ?o ?start ?finish
WHERE {
BIND(<%s> as ?kind_of_association)
?from hqdm:temporal_part_of <%s>;
hqdm:participant_in ?association.
?association hqdm:member_of_kind ?kind_of_association.
?participant hqdm:participant_in ?association;
hqdm:temporal_part_of ?s.
?s ?p ?o.
FILTER(?s != <%s>)
OPTIONAL {
?association hqdm:beginning ?begin.
?begin hqdm:data_EntityName ?start.
}
OPTIONAL {
?association hqdm:ending ?end.
?end hqdm:data_EntityName ?finish.
}
}
UNION
{
select distinct ?s ?p ?o
WHERE {
BIND(<%s> as ?kind_of_association)
?from hqdm:temporal_part_of <%s>;
hqdm:participant_in ?association.
?association hqdm:member_of_kind ?kind_of_association.
?participant hqdm:participant_in ?association;
hqdm:temporal_part_of ?s;
hqdm:member_of_kind ?role.
FILTER(?s != <%s>)
?role hqdm:data_EntityName ?o;
?p ?o.
}
}
UNION
{
select distinct ?s ?p ?o ?start ?finish
WHERE {
BIND(<%s> as ?kind_of_association)
?from hqdm:temporal_part_of <%s>;
hqdm:participant_in ?association.
?association hqdm:member_of_kind ?kind_of_association.
?participant hqdm:participant_in ?association;
hqdm:temporal_part_of ?s;
hqdm:member_of_kind ?role.
FILTER(?s != <%s>)
OPTIONAL {
?association hqdm:beginning ?begin.
?begin hqdm:data_EntityName ?start.
}
OPTIONAL {
?association hqdm:ending ?end.
?end hqdm:data_EntityName ?finish.
}
?role hqdm:data_EntityName ?o;
?p ?o.
}
UNION
{
select distinct ?s ?p ?o
WHERE {
BIND(<%s> as ?kind_of_association)
?from hqdm:temporal_part_of <%s>;
hqdm:participant_in ?association.
?association hqdm:member_of_kind ?kind_of_association.
?participant hqdm:participant_in ?association;
hqdm:temporal_part_of ?s.
FILTER(?s != <%s>)
?state_of_individual hqdm:temporal_part_of ?s.
?repBySign hqdm:represents ?state_of_individual.
?repBySign a hqdm:representation_by_sign.
?state_of_sign hqdm:participant_in ?repBySign;
a hqdm:state_of_sign;
hqdm:temporal_part_of ?sign.
?sign hqdm:value_ ?o;
?p ?o.
}
}
UNION
{
select distinct ?s ?p ?o ?start ?finish
WHERE {
BIND(<%s> as ?kind_of_association)
?from hqdm:temporal_part_of <%s>;
hqdm:participant_in ?association.
?association hqdm:member_of_kind ?kind_of_association.
?participant hqdm:participant_in ?association;
hqdm:temporal_part_of ?s.
FILTER(?s != <%s>)
?state_of_individual hqdm:temporal_part_of ?s.
?repBySign hqdm:represents ?state_of_individual.
?repBySign a hqdm:representation_by_sign.
?state_of_sign hqdm:participant_in ?repBySign;
a hqdm:state_of_sign;
hqdm:temporal_part_of ?sign.
OPTIONAL {
?association hqdm:beginning ?begin.
?begin hqdm:data_EntityName ?start.
}
OPTIONAL {
?association hqdm:ending ?end.
?end hqdm:data_EntityName ?finish.
}
?sign hqdm:value_ ?o;
?p ?o.
}
}
order by ?s ?p ?o
}
order by ?s ?p ?o
""";

/**
Expand Down

0 comments on commit 86af1d8

Please sign in to comment.