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

Gh 78 find associated at point in time #79

Merged
merged 7 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
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