Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Gh 80 add finder for activity references #81

Merged
merged 7 commits into from
Jan 13, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,40 @@ public List<? extends Thing> 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<? extends Thing> findByPartialSignByActivityReferenceAndClassCaseSensitive(final IRI wholeIri,
final String text, final IRI classIri,
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_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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: <http://www.semanticweb.org/hqdm#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

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.
*/
Expand Down