diff --git a/inception/inception-concept-linking/src/main/java/de/tudarmstadt/ukp/inception/conceptlinking/service/ConceptLinkingServiceImpl.java b/inception/inception-concept-linking/src/main/java/de/tudarmstadt/ukp/inception/conceptlinking/service/ConceptLinkingServiceImpl.java index 1f6179c64b1..fccc926510f 100644 --- a/inception/inception-concept-linking/src/main/java/de/tudarmstadt/ukp/inception/conceptlinking/service/ConceptLinkingServiceImpl.java +++ b/inception/inception-concept-linking/src/main/java/de/tudarmstadt/ukp/inception/conceptlinking/service/ConceptLinkingServiceImpl.java @@ -434,10 +434,10 @@ private CandidateEntity initCandidate(CandidateEntity candidate, String aQuery, public List rankCandidates(String aQuery, String aMention, Set aCandidates, CAS aCas, int aBegin) { - long startTime = currentTimeMillis(); + var startTime = currentTimeMillis(); // Set the feature values - List candidates = aCandidates.stream() // + var candidates = aCandidates.stream() // .map(CandidateEntity::new) // .map(candidate -> initCandidate(candidate, aQuery, aMention, aCas, aBegin)) .map(candidate -> { @@ -452,7 +452,7 @@ public List rankCandidates(String aQuery, String aMention, Set results = candidates.stream() // + var results = candidates.stream() // .map(candidate -> { KBHandle handle = candidate.getHandle(); handle.setDebugInfo(String.valueOf(candidate.getFeatures())); @@ -463,13 +463,13 @@ public List rankCandidates(String aQuery, String aMention, Set selectedConcept; private IModel kbModel; private IModel options; + private AbstractTree tree; public ConceptTreePanel(String aId, IModel aKbModel, IModel selectedConceptModel) @@ -68,7 +75,25 @@ public ConceptTreePanel(String aId, IModel aKbModel, kbModel = aKbModel; options = Model.of(new ConceptTreeProviderOptions()); - AbstractTree tree = new DefaultNestedTree("tree", + tree = createConceptTree(); + add(tree); + + var addLink = new LambdaAjaxLink("add", + _target -> send(getPage(), Broadcast.BREADTH, new AjaxNewConceptEvent(_target))); + addLink.add(new Label("label", new ResourceModel("concept.list.add"))); + addLink.add(new WriteProtectionBehavior(kbModel)); + add(addLink); + + var form = new Form("form", CompoundPropertyModel.of(options)); + form.add(new CheckBox("showAllConcepts").setOutputMarkupId(true) // + .add(new LambdaAjaxFormSubmittingBehavior("change", + this::actionPreferenceChanged))); + add(form); + } + + private DefaultNestedTree createConceptTree() + { + return new DefaultNestedTree("tree", new ConceptTreeProvider(kbService, kbModel, options), Model.ofSet(new HashSet<>())) { private static final long serialVersionUID = -270550186750480253L; @@ -112,27 +137,29 @@ protected boolean isSelected() }; } }; - add(tree); - - LambdaAjaxLink addLink = new LambdaAjaxLink("add", - target -> send(getPage(), Broadcast.BREADTH, new AjaxNewConceptEvent(target))); - addLink.add(new Label("label", new ResourceModel("concept.list.add"))); - addLink.add(new WriteProtectionBehavior(kbModel)); - add(addLink); + } - Form form = new Form<>("form", - CompoundPropertyModel.of(options)); - form.add(new CheckBox("showAllConcepts").setOutputMarkupId(true) // - .add(new LambdaAjaxFormSubmittingBehavior("change", - this::actionPreferenceChanged))); - add(form); + @OnEvent + public void onConceptSelectionEvent(AjaxConceptSelectionEvent aEvent) + { + // Try expanding the path to the selected concept + if (selectedConcept.isPresent().getObject()) { + var c = (KBObject) selectedConcept.getObject(); + var parents = kbService.getParentConceptList(c.getKB(), c.getIdentifier(), false); + LOG.debug("Trying to expand {}", parents); + for (var h : parents) { + tree.expand(h); + } + aEvent.getTarget().add(this); + aEvent.getTarget().appendJavaScript("document.querySelector('#" + getMarkupId() + + " .selected')?.scrollIntoView({block: 'center'});"); + } } private void actionSelectionChanged(AjaxRequestTarget aTarget) { // if the selection changes, publish an event denoting the change - AjaxConceptSelectionEvent e = new AjaxConceptSelectionEvent(aTarget, - selectedConcept.getObject().toKBHandle()); + var e = new AjaxConceptSelectionEvent(aTarget, selectedConcept.getObject().toKBHandle()); send(getPage(), Broadcast.BREADTH, e); } diff --git a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/ConceptTreeProvider.java b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/ConceptTreeProvider.java index c953d364911..117378739c3 100644 --- a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/ConceptTreeProvider.java +++ b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/ConceptTreeProvider.java @@ -99,7 +99,7 @@ public boolean hasChildren(KBObject aNode) // To avoid having to send a query to the KB for every child node, just assume // that there might be child nodes and show the expander until we have actually // loaded the children, cached them and can show the true information. - List children = childrensCache.get(aNode); + var children = childrensCache.get(aNode); if (children == null) { return true; } @@ -135,7 +135,7 @@ public Iterator getChildren(KBObject aNode) try { // If the KB is read-only, then we cache the values and re-use the cached values. if (kbModel.getObject().isReadOnly()) { - List children = childrensCache.get(aNode); + var children = childrensCache.get(aNode); if (children == null) { children = kbService.listChildConcepts(kbModel.getObject(), aNode.getIdentifier(), options.getObject().isShowAllConcepts()); diff --git a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/KnowledgeBasePanel.java b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/KnowledgeBasePanel.java index a45e140a9d1..02ff956b78d 100644 --- a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/KnowledgeBasePanel.java +++ b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/KnowledgeBasePanel.java @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import org.apache.wicket.AttributeModifier; import org.apache.wicket.Component; @@ -151,16 +150,16 @@ public KnowledgeBasePanel(String id, IModel aProjectModel, private KnowledgeBaseItemAutoCompleteField createSearchField(String aId, IModel aHandleModel, IModel aProjectModel) { - KnowledgeBaseItemAutoCompleteField field = new KnowledgeBaseItemAutoCompleteField(aId, - aHandleModel, _query -> listSearchResults(aProjectModel.getObject(), _query)) + var field = new KnowledgeBaseItemAutoCompleteField(aId, aHandleModel, + _query -> listSearchResults(aProjectModel.getObject(), _query)) { private static final long serialVersionUID = 3188821013226116770L; @Override protected void onSelected(AjaxRequestTarget aTarget) { - KBHandle selectedResource = this.getModelObject(); - Optional optKbObject = kbService.readItem(kbModel.getObject(), + var selectedResource = this.getModelObject(); + var optKbObject = kbService.readItem(kbModel.getObject(), selectedResource.getIdentifier()); if (!optKbObject.isPresent()) { @@ -186,12 +185,10 @@ protected void onSelected(AjaxRequestTarget aTarget) */ private List listSearchResults(Project aProject, String aTypedString) { - List results; - KnowledgeBase kb = kbModel.getObject(); - results = conceptLinkingService.searchItems(kb, aTypedString).stream() - .limit(entityLinkingProperties.getCandidateDisplayLimit()) - .collect(Collectors.toList()); - return results; + var kb = kbModel.getObject(); + return conceptLinkingService.searchItems(kb, aTypedString).stream() // + .limit(entityLinkingProperties.getCandidateDisplayLimit()) // + .toList(); } /** @@ -204,8 +201,8 @@ private void sendSelectionChangedEvents(AjaxRequestTarget aTarget, KBObject aKbO new AjaxConceptSelectionEvent(aTarget, KBHandle.of(aKbObject), true)); } else if (aKbObject instanceof KBInstance) { - List conceptsForInstance = kbService - .getConceptForInstance(kbModel.getObject(), aKbObject.getIdentifier(), true); + var conceptsForInstance = kbService.getConceptForInstance(kbModel.getObject(), + aKbObject.getIdentifier(), true); if (!conceptsForInstance.isEmpty()) { send(getPage(), Broadcast.BREADTH, diff --git a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/KnowledgeBaseDetailsPanel.java b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/KnowledgeBaseDetailsPanel.java index c877366ee2a..77a99497ed9 100644 --- a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/KnowledgeBaseDetailsPanel.java +++ b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/KnowledgeBaseDetailsPanel.java @@ -23,11 +23,8 @@ import static java.util.Collections.emptyMap; import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCauseMessage; -import java.io.File; import java.io.FileInputStream; -import java.io.InputStream; -import org.apache.commons.lang3.tuple.Pair; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.feedback.IFeedback; import org.apache.wicket.markup.html.form.Form; @@ -147,7 +144,7 @@ private void actionSave(AjaxRequestTarget aTarget, Form aF aTarget.add(this); try { - KnowledgeBaseWrapper kbw = kbwModel.getObject(); + var kbw = kbwModel.getObject(); // if dealing with a remote repository and a non-empty URL, get a new // RepositoryImplConfig for the new URL; otherwise keep using the existing config @@ -167,8 +164,8 @@ private void actionSave(AjaxRequestTarget aTarget, Form aF if (kb.getType() == LOCAL) { kbService.defineBaseProperties(kb); - for (Pair f : kbw.getFiles()) { - try (InputStream is = new FileInputStream(f.getValue())) { + for (var f : kbw.getFiles()) { + try (var is = new FileInputStream(f.getValue())) { kbService.importData(kb, f.getValue().getName(), is); success("Imported: " + f.getKey()); } diff --git a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/ProjectKnowledgeBasePanel.properties b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/ProjectKnowledgeBasePanel.properties index c15a4c1508b..b91e2bf6b57 100644 --- a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/ProjectKnowledgeBasePanel.properties +++ b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/ProjectKnowledgeBasePanel.properties @@ -60,6 +60,7 @@ kb.wizard.steps.accessSpecific.description=Description kb.wizard.steps.accessSpecific.hostInstitutionName=Host Institution kb.wizard.steps.accessSpecific.authorName=Author(s) kb.wizard.steps.accessSpecific.homepage=Homepage +kb.wizard.steps.accessSpecific.license=License kb.wizard.title=New Knowledge Base kb.settings.general = General Settings @@ -102,7 +103,7 @@ kb.export.nt=N-Triples RepositoryType.LOCAL=Local RepositoryType.REMOTE=Remote (SPARQL) -kb.reification = Reification +kb.reification = Reification SchemaProfile.RDFSCHEMA=RDF SchemaProfile.OWLSCHEMA=OWL diff --git a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/local/LocalRepositorySettingsPanel.java b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/local/LocalRepositorySettingsPanel.java index f5a71e4b135..e8585a7c766 100644 --- a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/local/LocalRepositorySettingsPanel.java +++ b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/local/LocalRepositorySettingsPanel.java @@ -389,25 +389,25 @@ private void actionDownloadKbAndSetIRIs(AjaxRequestTarget aTarget) { try { if (selectedKnowledgeBaseProfile != null) { - String accessUrl = selectedKnowledgeBaseProfile.getAccess().getAccessUrl(); + var accessUrl = selectedKnowledgeBaseProfile.getAccess().getAccessUrl(); - FileUploadDownloadHelper fileUploadDownloadHelper = new FileUploadDownloadHelper( - getApplication()); + var fileUploadDownloadHelper = new FileUploadDownloadHelper(getApplication()); - if (!accessUrl.startsWith(CLASSPATH_PREFIX)) { - File tmpFile = fileUploadDownloadHelper - .writeFileDownloadToTemporaryFile(accessUrl, getModel()); - getModel().getObject().putFile(selectedKnowledgeBaseProfile.getName(), tmpFile); - } - else { + if (accessUrl.startsWith(CLASSPATH_PREFIX)) { // import from classpath - File kbFile = fileUploadDownloadHelper + var kbFile = fileUploadDownloadHelper .writeClasspathResourceToTemporaryFile(accessUrl, getModel()); getModel().getObject().putFile(selectedKnowledgeBaseProfile.getName(), kbFile); } + else if (accessUrl != null) { + var tmpFile = fileUploadDownloadHelper + .writeFileDownloadToTemporaryFile(accessUrl, getModel()); + getModel().getObject().putFile(selectedKnowledgeBaseProfile.getName(), tmpFile); + } - KnowledgeBase kb = getModel().getObject().getKb(); + var kb = getModel().getObject().getKb(); kb.applyRootConcepts(selectedKnowledgeBaseProfile); + kb.applyAdditionalMatchingProperties(selectedKnowledgeBaseProfile); kb.applyMapping(selectedKnowledgeBaseProfile.getMapping()); kb.setFullTextSearchIri( selectedKnowledgeBaseProfile.getAccess().getFullTextSearchIri()); diff --git a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/remote/RemoteRepositorySettingsPanel.java b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/remote/RemoteRepositorySettingsPanel.java index d4f93f7f2fa..1344038f758 100644 --- a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/remote/RemoteRepositorySettingsPanel.java +++ b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/project/remote/RemoteRepositorySettingsPanel.java @@ -42,7 +42,6 @@ import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; -import de.tudarmstadt.ukp.inception.kb.model.KnowledgeBase; import de.tudarmstadt.ukp.inception.kb.yaml.KnowledgeBaseInfo; import de.tudarmstadt.ukp.inception.kb.yaml.KnowledgeBaseProfile; import de.tudarmstadt.ukp.inception.security.client.auth.AuthenticationTraitsEditor; @@ -219,11 +218,11 @@ protected void populateItem(ListItem item) private void actionPopulate(AjaxRequestTarget aTarget, KnowledgeBaseProfile aProfile) { // set all the fields according to the chosen profile - KnowledgeBaseWrapper kbw = getModel().getObject(); + var kbw = getModel().getObject(); kbw.setUrl(aProfile.getAccess().getAccessUrl()); // sets root concepts list - if null then an empty list otherwise change the // values to IRI and populate the list - KnowledgeBase kb = kbw.getKb(); + var kb = kbw.getKb(); kb.applyRootConcepts(aProfile); kb.applyAdditionalMatchingProperties(aProfile); kb.applyMapping(aProfile.getMapping());