Skip to content

Commit

Permalink
Merge branch 'main' into feature/2696-Document-level-recommendations
Browse files Browse the repository at this point in the history
* main:
  #4381 - Allow users to browse their past activity
  #4381 - Allow users to browse their past activity
  #4381 - Allow users to browse their past activity
  #4381 - Allow users to browse their past activity
  #4381 - Allow users to browse their past activity
  • Loading branch information
reckart committed Dec 17, 2023
2 parents 6e7b0f2 + 3310158 commit 11c5211
Show file tree
Hide file tree
Showing 40 changed files with 1,124 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public interface ActiveLearningService
List<SuggestionGroup<SpanSuggestion>> getSuggestions(User aDataOwner, AnnotationLayer aLayer);

/**
* @return if the are any records of type {@link LearningRecordUserAction#SKIPPED} in the history of
* the given layer for the given user.
* @return if the are any records of type {@link LearningRecordUserAction#SKIPPED} in the
* history of the given layer for the given user.
*
* @param aDataOwner
* annotator user to check suggestions for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void onConfigure()
super.addFeatureUpdateBehavior();
featureUpdateBehaviorAdded = true;
}

// Hides feature if "Hide un-constraint feature" is enabled and constraint rules are applied
// and feature doesn't match any constraint rule
// if enabled and constraints rule execution returns anything other than green
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@

/**
* <p>
* This class is exposed as a Spring Component via {@link DiamCompactV2AutoConfig#compactSerializerV2}.
* This class is exposed as a Spring Component via
* {@link DiamCompactV2AutoConfig#compactSerializerV2}.
* </p>
*/
public class CompactSerializerV2Impl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public class CompactSerializerV2ImplTest
{
private @Mock AnnotationSchemaProperties annotationSchemaProperties;

@Test
void thatSerializationWorks() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void setup()
@Override
public void build(int aIndex, Builder aBuilder)
{
// This should hopefully allow running tests on machines with less than the
// This should hopefully allow running tests on machines with less than the
// default 90% high watermark disk space free (e.g on a 1TB drive less than 100 GB).
aBuilder.put("cluster.routing.allocation.disk.threshold_enabled", false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ public void thatExecuteQueryWorks() throws Exception
public void thatGetDocumentTextWorks() throws Exception
{
when(annotationService.getFullProjectTypeSystem(any()))
.thenReturn(createTypeSystemDescription());
.thenReturn(createTypeSystemDescription());

String results = sut.getDocumentText(repo, traits, "PMC", "PMC7096989");

// System.out.println(results);

assertThat(results).contains("Asthma is the most common inflammatory disease of the lungs.");
assertThat(results)
.contains("Asthma is the most common inflammatory disease of the lungs.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ public void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD,
{
aTD.addFeature(aFeature.getName(), "", CAS.TYPE_NAME_STRING);
}

@Override
public List<VLazyDetailGroup> lookupLazyDetails(AnnotationFeature aFeature, Object aValue)
{
if (aValue instanceof LookupEntry) {
var handle = (LookupEntry) aValue;

var result = new VLazyDetailGroup();
result.addDetail(new VLazyDetail("Label", handle.getUiLabel()));

Expand All @@ -249,7 +249,7 @@ public List<VLazyDetailGroup> lookupLazyDetails(AnnotationFeature aFeature, Obje

return asList(result);
}

return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ protected AnnotationEditorProperties getProperties()
props.setEditorFactoryId(getFactory().getBeanName());
if (getFactory() instanceof ClientSideUserPreferencesProvider) {
((ClientSideUserPreferencesProvider) getFactory()).getUserPreferencesKey()
.ifPresent(key -> props.setUserPreferencesKey(key.getClientSideKey()));
.ifPresent(key -> props.setUserPreferencesKey(key.getClientSideKey()));
}
props.setDiamAjaxCallbackUrl(getDiamBehavior().getCallbackUrl().toString());
props.setStylesheetSources(
asList(referenceToUrl(servletContext, ApacheAnnotatorJsCssResourceReference.get())));
props.setScriptSources(asList(
referenceToUrl(servletContext, ApacheAnnotatorJsJavascriptResourceReference.get())));
props.setStylesheetSources(asList(
referenceToUrl(servletContext, ApacheAnnotatorJsCssResourceReference.get())));
props.setScriptSources(asList(referenceToUrl(servletContext,
ApacheAnnotatorJsJavascriptResourceReference.get())));
return props;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public int accepts(Project aProject, String aFormat)
if (aFormat.startsWith(CustomXmlFormatLoader.CUSTOM_XML_FORMAT_PREFIX)) {
return PREFERRED;
}

switch (aFormat) {
case HtmlFormatSupport.ID: // fall-through
case XmlFormatSupport.ID:
Expand Down Expand Up @@ -105,8 +105,8 @@ public void initState(AnnotatorState aModelObject)
@Override
public Optional<ClientSidePreferencesKey<Map>> getUserPreferencesKey()
{
return Optional
.of(new ClientSidePreferencesKey<>(Map.class, "annotation/apache-annotator-editor"));
return Optional.of(
new ClientSidePreferencesKey<>(Map.class, "annotation/apache-annotator-editor"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@Configuration
@ConditionalOnProperty(prefix = "ui.html-apacheannotator", name = "enabled", //
havingValue = "true", matchIfMissing = true)
havingValue = "true", matchIfMissing = true)
public class ApacheAnnotatorHtmlAnnotationEditorSupportAutoConfiguration
{
@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public void setTrainable(boolean aTrainable)
{
trainable = aTrainable;
}

public void setVerifyCertificates(boolean aVerifyCertificates)
{
verifyCertificates = aVerifyCertificates;
}

public boolean isVerifyCertificates()
{
return verifyCertificates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public Range predict(RecommenderContext aContext, CAS aCas, int aBegin, int aEnd
throws RecommendationException
{
var responseExtractor = getResponseExtractor();
List<MentionsSample> examples = responseExtractor.generate(this, aCas, MAX_FEW_SHOT_EXAMPLES);
List<MentionsSample> examples = responseExtractor.generate(this, aCas,
MAX_FEW_SHOT_EXAMPLES);

getPromptContextGenerator().generate(this, aCas, aBegin, aEnd).forEach(promptContext -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class ResponseAsLabelExtractor
private final static Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

@Override
public List<MentionsSample> generate(RecommendationEngine aEngine, CAS aCas,
int aNum)
public List<MentionsSample> generate(RecommendationEngine aEngine, CAS aCas, int aNum)
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public final class TeiConstants
public static final String ATTR_LEMMA = "lemma";

public static final String ATTR_XML_ID = "xml:id";

public static final String TEI_NS = "http://www.tei-c.org/ns/1.0";
public static final QName E_TEI_TEI = new QName(TEI_NS, TAG_TEI_DOC);
public static final QName E_TEI_HEADER = new QName(TEI_NS, "teiHeader");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,10 @@ public void getNext(CAS aCAS) throws IOException, CollectionException
(TypePriorities) null, (FsIndexDescription[]) null).getJCas();

// Create a holder for the CAS metadata
var cms = Serialization
.serializeCASMgr((mergedTypeSystemCas).getCasImpl());
var cms = Serialization.serializeCASMgr((mergedTypeSystemCas).getCasImpl());

// Reinitialize CAS with merged type system
((CASImpl) aCAS).getBinaryCasSerDes()
.setupCasFromCasMgrSerializer(cms);
((CASImpl) aCAS).getBinaryCasSerDes().setupCasFromCasMgrSerializer(cms);
}
catch (CASException | ResourceInitializationException e) {
throw new CollectionException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
*/
package de.tudarmstadt.ukp.inception.log;

import java.time.Instant;
import java.util.Collection;
import java.util.List;

import org.apache.commons.lang3.function.FailableConsumer;

import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.inception.log.model.LoggedEvent;
import de.tudarmstadt.ukp.inception.log.model.SummarizedLoggedEvent;

public interface EventRepository
{
Expand Down Expand Up @@ -100,4 +102,7 @@ List<LoggedEvent> listRecentActivity(Project aProject, String aUsername,
* return this number of recent events or less
*/
List<LoggedEvent> listRecentActivity(String aUsername, int aMaxSize);

List<SummarizedLoggedEvent> summarizeEvents(String aUsername, Project aProject, Instant aNow,
Instant aMinus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@
package de.tudarmstadt.ukp.inception.log;

import static java.lang.String.join;
import static java.time.temporal.ChronoUnit.DAYS;

import java.lang.invoke.MethodHandles;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Stream;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Tuple;

import org.apache.commons.lang3.function.FailableConsumer;
import org.apache.commons.lang3.stream.Streams;
Expand All @@ -41,6 +47,8 @@
import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.inception.log.config.EventLoggingAutoConfiguration;
import de.tudarmstadt.ukp.inception.log.model.LoggedEvent;
import de.tudarmstadt.ukp.inception.log.model.LoggedEvent_;
import de.tudarmstadt.ukp.inception.log.model.SummarizedLoggedEvent;

/**
* <p>
Expand Down Expand Up @@ -213,4 +221,41 @@ public <E extends Throwable> void forEachLoggedEvent(Project aProject,
Streams.failableStream(eventStream).forEach(aConsumer);
}
}

@Override
public List<SummarizedLoggedEvent> summarizeEvents(String aUsername, Project aProject,
Instant aFrom, Instant aTo)
{
var cb = entityManager.getCriteriaBuilder();
var query = cb.createQuery(Tuple.class);
var root = query.from(LoggedEvent.class);

query //
.multiselect( //
root.get(LoggedEvent_.created), //
root.get(LoggedEvent_.document), //
root.get(LoggedEvent_.event))
.where( //
cb.equal(root.get(LoggedEvent_.user), aUsername), //
cb.equal(root.get(LoggedEvent_.project), aProject.getId()), //
cb.between(root.get(LoggedEvent_.created), Date.from(aFrom),
Date.from(aTo)));

var aggregator = new HashMap<SummarizedLoggedEventKey, AtomicLong>();

entityManager.createQuery(query).getResultStream().forEach(tuple -> {
var truncDate = tuple.get(0, Date.class).toInstant().truncatedTo(DAYS);
var document = tuple.get(1, Long.class);
var event = tuple.get(2, String.class);
var key = new SummarizedLoggedEventKey(event, truncDate, document);
aggregator.computeIfAbsent(key, $ -> new AtomicLong()).addAndGet(1);
});

return aggregator.entrySet().stream() //
.map(e -> new SummarizedLoggedEvent(e.getKey().event(), e.getKey().document(),
e.getKey().date(), e.getValue().get())) //
.toList();
}

private static record SummarizedLoggedEventKey(String event, Instant date, long document) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Technische Universität Darmstadt under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The Technische Universität Darmstadt
* licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.tudarmstadt.ukp.inception.log.model;

import java.time.Instant;

public class SummarizedLoggedEvent
{
private final long document;
private final String event;
private final Instant date;
private final long count;

public SummarizedLoggedEvent(String aEvent, long aDocument, Instant aDate, long aCount)
{
document = aDocument;
event = aEvent;
date = aDate;
count = aCount;
}

public Instant getDate()
{
return date;
}

public long getCount()
{
return count;
}

public String getEvent()
{
return event;
}

public long getDocument()
{
return document;
}
}
Loading

0 comments on commit 11c5211

Please sign in to comment.