diff --git a/core/src/main/java/uk/gov/gchq/magmacore/service/MagmaCoreService.java b/core/src/main/java/uk/gov/gchq/magmacore/service/MagmaCoreService.java index 80fa222a..a7418aac 100644 --- a/core/src/main/java/uk/gov/gchq/magmacore/service/MagmaCoreService.java +++ b/core/src/main/java/uk/gov/gchq/magmacore/service/MagmaCoreService.java @@ -345,6 +345,40 @@ public List findByPartialSignAndClassCaseSensitive(final String } + /** + * A case-sensitive search for entities in a specified class with a sign containing the given text + * that are referenced by an activity. + * + * @param wholeIri The object that the required entities are composed into. + * @param text The String to search for. + * @param classIri The IRI of the class that the entities should be a member_of. + * @param pointInTime When the entities should have the matching sign. + * @return A {@link List} of {@link Thing}. + */ + public List findByPartialSignByActivityReferenceAndClassCaseSensitive(final IRI wholeIri, + final String text, final IRI classIri, + final PointInTime pointInTime) { + + final Set 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_MEMBERS_OF_CLASS_BY_ACTIVITY_AND_PARTIAL_SIGN_CASE_SENSITIVE, + text, classIri, wholeIri, + text, classIri, wholeIri, + text, classIri, wholeIri)); + + // Filter by the pointInTime + 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 * that are parts of a given whole. diff --git a/core/src/main/java/uk/gov/gchq/magmacore/service/sparql/MagmaCoreServiceQueries.java b/core/src/main/java/uk/gov/gchq/magmacore/service/sparql/MagmaCoreServiceQueries.java index 8088e1b1..b84d34d4 100644 --- a/core/src/main/java/uk/gov/gchq/magmacore/service/sparql/MagmaCoreServiceQueries.java +++ b/core/src/main/java/uk/gov/gchq/magmacore/service/sparql/MagmaCoreServiceQueries.java @@ -544,6 +544,105 @@ public class MagmaCoreServiceQueries { order by ?s ?p ?o """; + /** + * A partial search by sign for entities referenced by an Activity. + */ + public static final String FIND_MEMBERS_OF_CLASS_BY_ACTIVITY_AND_PARTIAL_SIGN_CASE_SENSITIVE = """ + PREFIX hqdm: + PREFIX rdf: + + SELECT distinct ?s ?p ?o ?start ?finish + WHERE { + { + SELECT ?s ?p ?o ?start ?finish + WHERE { + BIND("%s" as ?text) + BIND(<%s> as ?class) + BIND(<%s> as ?topicId) + + ?sign hqdm:value_ ?signvalue; + hqdm:member_of_ ?pattern. + FILTER(CONTAINS(str(?signvalue), ?text)) + ?sos hqdm:temporal_part_of ?sign; + hqdm:participant_in ?repBySign. + ?rlc hqdm:participant_in ?repBySign. + ?repBySign hqdm:represents ?state. + ?state hqdm:temporal_part_of ?s. + ?s hqdm:member_of ?class. + ?topicId hqdm:references ?s. + ?s ?p ?o. + OPTIONAL { + ?repBySign hqdm:beginning ?begin. + ?begin hqdm:data_EntityName ?start. + } + OPTIONAL { + ?repBySign hqdm:ending ?end. + ?end hqdm:data_EntityName ?finish. + } + } + } + UNION + { + SELECT ?s (hqdm:value_ as ?p) ?o ?start ?finish + WHERE { + BIND("%s" as ?text) + BIND(<%s> as ?class) + BIND(<%s> as ?topicId) + + ?sign hqdm:value_ ?o; + hqdm:member_of_ ?pattern. + FILTER(CONTAINS(str(?o), ?text)) + ?sos hqdm:temporal_part_of ?sign; + hqdm:participant_in ?repBySign. + ?rlc hqdm:participant_in ?repBySign. + ?repBySign hqdm:represents ?state. + ?state hqdm:temporal_part_of ?s. + ?s hqdm:member_of ?class. + ?topicId hqdm:references ?s. + OPTIONAL { + ?repBySign hqdm:beginning ?begin. + ?begin hqdm:data_EntityName ?start. + } + OPTIONAL { + ?repBySign hqdm:ending ?end. + ?end hqdm:data_EntityName ?finish. + } + } + } + UNION + { + SELECT ?s (hqdm:data_EntityName as ?p) ?o ?start ?finish + WHERE { + BIND("%s" as ?text) + BIND(<%s> as ?class) + BIND(<%s> as ?topicId) + + ?sign hqdm:value_ ?signValue; + hqdm:member_of_ ?pattern. + FILTER(CONTAINS(str(?signValue), ?text)) + ?sos hqdm:temporal_part_of ?sign; + hqdm:participant_in ?repBySign. + ?rlc hqdm:participant_in ?repBySign. + ?repBySign hqdm:represents ?state. + ?state hqdm:temporal_part_of ?s. + ?s hqdm:member_of ?class. + ?topicId hqdm:references ?s. + ?s hqdm:member_of_kind ?kind. + ?kind hqdm:data_EntityName ?o. + OPTIONAL { + ?repBySign hqdm:beginning ?begin. + ?begin hqdm:data_EntityName ?start. + } + OPTIONAL { + ?repBySign hqdm:ending ?end. + ?end hqdm:data_EntityName ?finish. + } + } + } + } + order by ?s ?p ?o + """; + /** * A partial search by sign for entities composed into a whole entity. */