Skip to content

Commit

Permalink
Merge branch 'main' into feature/4907-Support-for-DocX
Browse files Browse the repository at this point in the history
* main:
  #5047 - Clean up layer detail UI a bit
  #4949 - Showing the start and end points of relations in left side bar
  No issue: Minor cleaning up
  #5043 - Ability to specify token breaking zones when calling tokenizer
  #4904 - Upgrade to RDF4J 5.x
  • Loading branch information
reckart committed Sep 8, 2024
2 parents 4c607bf + ccd189e commit 160abac
Show file tree
Hide file tree
Showing 28 changed files with 302 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@

import static de.tudarmstadt.ukp.inception.support.io.ZipUtils.zipFolder;
import static java.io.File.createTempFile;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableSet;
import static java.util.Optional.empty;
import static org.apache.commons.io.FileUtils.copyFile;
import static org.apache.commons.io.FilenameUtils.getBaseName;
import static org.apache.commons.io.FilenameUtils.getExtension;
import static org.apache.commons.lang3.StringUtils.rightPad;
import static org.apache.uima.fit.factory.AnalysisEngineFactory.createEngine;
import static org.apache.uima.fit.factory.CollectionReaderFactory.createReader;
import static org.apache.uima.fit.factory.ConfigurationParameterFactory.addConfigurationParameters;
Expand All @@ -32,13 +36,10 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
Expand Down Expand Up @@ -124,20 +125,20 @@ default InputStream openResourceStream(File aDocFile, String aResourcePath) thro
*/
default List<ResourceReference> getCssStylesheets()
{
return Collections.emptyList();
return emptyList();
}

/**
* @return format-specific section elements
*/
default List<String> getSectionElements()
{
return Collections.emptyList();
return emptyList();
}

default Optional<PolicyCollection> getPolicy() throws IOException
{
return Optional.empty();
return empty();
}

/**
Expand Down Expand Up @@ -203,7 +204,7 @@ default File write(SourceDocument aDocument, CAS aCas, File aTargetFolder,
boolean aStripExtension)
throws ResourceInitializationException, AnalysisEngineProcessException, IOException
{
AnalysisEngineDescription writer = getWriterDescription(aDocument.getProject(), null, aCas);
var writer = getWriterDescription(aDocument.getProject(), null, aCas);
addConfigurationParameters(writer, //
JCasFileWriter_ImplBase.PARAM_USE_DOCUMENT_ID, true,
JCasFileWriter_ImplBase.PARAM_ESCAPE_FILENAME, false,
Expand All @@ -225,21 +226,18 @@ default File write(SourceDocument aDocument, CAS aCas, File aTargetFolder,

// If the writer produced more than one file, we package it up as a ZIP file
if (aTargetFolder.listFiles().length > 1) {
File exportFile = createTempFile("inception-document", ".zip");
// File exportFile = new File(aTargetFolder.getAbsolutePath() + ".zip");
var exportFile = createTempFile("inception-document", ".zip");
zipFolder(aTargetFolder, exportFile);
return exportFile;
}

// If the writer produced only a single file, then that is the result
String filename = FilenameUtils.getBaseName(aTargetFolder.listFiles()[0].getName());
var exportedFile = aTargetFolder.listFiles()[0];
// temp-file prefix must be at least 3 chars
filename = StringUtils.rightPad(filename, 3, "_");
File exportFile = createTempFile(filename,
"." + FilenameUtils.getExtension(aTargetFolder.listFiles()[0].getName()));
// File exportFile = new File(aTargetFolder.getParent(),
// aTargetFolder.listFiles()[0].getName());
copyFile(aTargetFolder.listFiles()[0], exportFile);
var baseName = rightPad(getBaseName(exportedFile.getName()), 3, "_");
var extension = getExtension(exportedFile.getName());
var exportFile = createTempFile(baseName, "." + extension);
copyFile(exportedFile, exportFile);
return exportFile;
}
}
30 changes: 4 additions & 26 deletions inception/inception-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1182,39 +1182,17 @@

<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-api</artifactId>
<artifactId>owlapi-bom</artifactId>
<version>${owlapi-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<!-- See https://github.com/owlcs/owlapi/issues/1154 -->
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-apibinding</artifactId>
<version>${owlapi-version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-impl</artifactId>
<version>${owlapi-version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-oboformat</artifactId>
<version>${owlapi-version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-parsers</artifactId>
<version>${owlapi-version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-rio</artifactId>
<version>${owlapi-version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-tools</artifactId>
<version>${owlapi-version}</version>
</dependency>

<dependency>
<groupId>com.github.jsonld-java</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public class CompactLayer
{
private final long id;
private final String name;
private final String type;

public CompactLayer(long aId, String aName)
public CompactLayer(long aId, String aName, String aType)
{
id = aId;
name = aName;
type = aType;
}

public long getId()
Expand All @@ -37,4 +39,9 @@ public String getName()
{
return name;
}

public String getType()
{
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void renderLayers(RenderRequest aRequest, CompactAnnotatedText aResponse
continue;
}

layers.add(new CompactLayer(layer.getId(), layer.getUiName()));
layers.add(new CompactLayer(layer.getId(), layer.getUiName(), layer.getType()));

for (VSpan vspan : aVDoc.spans(layer.getId())) {
var cspan = renderSpan(aRequest, vspan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"action" : "getAnnotatedDocument",
"layers" : [ {
"id" : 1,
"name" : "Span"
"name" : "Span",
"type" : "span"
}, {
"id" : 2,
"name" : "Relation"
"name" : "Relation",
"type" : "relation"
} ],
"text" : "This is a test.",
"window" : [ 0, 15 ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
return b.score - a.score;
}
return compareOffsets(targetA.offsets[0], targetB.offsets[0])
const targetA = a.arguments[0].target as Span
const targetB = b.arguments[0].target as Span
return compareOffsets(targetA.offsets[0], targetB.offsets[0]);
}
console.error("Unexpected annotation type combination", a, b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
import { compareOffsets } from "@inception-project/inception-js-api/src/model/Offsets";
import LabelBadge from "./LabelBadge.svelte";
import SpanText from "./SpanText.svelte";
import { compareSpanText, debounce, filterAnnotations, getCoveredText, groupBy, uniqueLayers } from "./Utils";
import { compareSpanText, debounce, filterAnnotations, groupRelationsBySource, groupBy, uniqueLayers } from "./Utils";
import { sortByScore, recommendationsFirst } from "./AnnotationBrowserState"
export let ajaxClient: DiamAjax;
export let data: AnnotatedText;
let groupedRelations: Record<string, Relation[]>;
let groupedAnnotations: Record<string, Annotation[]>;
let groups: { layer: Layer, collapsed: boolean }[]
let collapsedGroups = new Set<number>()
Expand All @@ -55,6 +56,8 @@
(s) => s.layer.name
)
groupedRelations = groupRelationsBySource(data);
for (let [key, items] of Object.entries(groupedAnnotations)) {
items = filterAnnotations(data, items, filter)
items.sort((a, b) => {
Expand Down Expand Up @@ -193,56 +196,112 @@
{#each groups as group}
<li class="list-group-item py-0 px-0 border-0">
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="px-2 py-1 bg-light-subtle fw-bold sticky-top border-top border-bottom"
on:click={() => toggleCollapsed(group)}
>
<button class="btn btn-link p-0" style="color: var(--bs-body-color)">
<i class="fas fa-caret-down d-inline-block" class:group-collapsed={group.collapsed}/>
</button>
<span>{group.layer.name}</span>
<span>{group.layer.name} {group.layer.type}</span>
</div>
<ul class="px-0 list-group list-group-flush" class:d-none={group.collapsed}>
{#if groupedAnnotations[group.layer.name]}
{#each groupedAnnotations[group.layer.name] as ann}
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<li
class="list-group-item list-group-item-action p-0 d-flex"
on:mouseover={ev => mouseOverAnnotation(ev, ann)}
on:mouseout={ev => mouseOutAnnotation(ev, ann)}
>
<div
class="text-secondary bg-light-subtle border-end px-2 d-flex align-items-center"
{#if ann instanceof Span}
<li
class="list-group-item list-group-item-action p-0 d-flex"
on:mouseover={ev => mouseOverAnnotation(ev, ann)}
on:mouseout={ev => mouseOutAnnotation(ev, ann)}
>
{#if ann instanceof Span}
<div class="annotation-type-marker i7n-icon-span"/>
{:else if ann instanceof Relation}
<div class="annotation-type-marker i7n-icon-relation"/>
{/if}
</div>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div
class="flex-grow-1 my-1 mx-2 position-relative overflow-hidden"
on:click={() => scrollTo(ann)}
>
<div class="float-end labels">
<LabelBadge
annotation={ann}
{ajaxClient}
showText={true}
/>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div class="flex-grow-1 my-1 mx-2 position-relative overflow-hidden" on:click={() => scrollTo(ann)}>
<div class="float-end labels me-1">
<LabelBadge
annotation={ann}
{ajaxClient}
showText={true}
/>
</div>
<SpanText {data} span={ann} />
</div>
</li>

{#if ann instanceof Span}
<SpanText {data} span={ann} />
{:else if ann instanceof Relation}
<SpanText
{data}
span={ann.arguments[0].target}
/>
{/if}
</div>
</li>
{@const relations = groupedRelations[`${ann.vid}`]}
{#if relations}
{#each relations as relation}
{@const target = relation.arguments[1].target}
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<li
class="list-group-item list-group-item-action p-0 d-flex"
on:mouseover={(ev) =>
mouseOverAnnotation(ev, relation)}
on:mouseout={(ev) =>
mouseOutAnnotation(ev, relation)}
>
<div
class="text-secondary bg-light-subtle border-end px-2 d-flex align-items-center"
>
<span>↳</span>
</div>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="flex-grow-1 my-1 mx-2 overflow-hidden"
on:click={() => scrollTo(target)}
>
<div class="float-end labels me-1">
<LabelBadge
annotation={relation}
{ajaxClient}
/>
</div>

<SpanText {data} span={target} />
</div>
</li>
{/each}
{/if}
{:else if ann instanceof Relation && group.layer.type === "relation"}
<li
class="list-group-item p-0 d-flex"
on:mouseover={ev => mouseOverAnnotation(ev, ann)}
on:mouseout={ev => mouseOutAnnotation(ev, ann)}
>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div class="flex-grow-1 my-1 mx-0 position-relative overflow-hidden">
<div class="me-2">
<LabelBadge
annotation={ann}
{ajaxClient}
showText={true}
/>
</div>
<div class="d-flex flex-row list-group-item-action" on:click={() => scrollTo(ann.arguments[0].target)}>
<div class="text-secondary bg-light-subtle border-end px-2 d-flex align-items-center">
<span style="transform: rotate(90deg);">↳</span>
</div>
<SpanText
{data}
span={ann.arguments[0].target}
/>
</div>
<div class="d-flex flex-row list-group-item-action" on:click={() => scrollTo(ann.arguments[1].target)}>
<div class="text-secondary bg-light-subtle border-end px-2 d-flex align-items-center">
<span>↳</span>
</div>
<SpanText
{data}
span={ann.arguments[1].target}
/>
</div>
</div>
</li>
{/if}
{/each}
{:else}
<li class="list-group-item list-group-item-action p-2 text-center text-secondary bg-light">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import LabelBadge from "./LabelBadge.svelte";
import SpanText from "./SpanText.svelte";
import {
debounce,
debounce,
groupRelationsByPosition,
groupSpansByPosition,
uniqueOffsets,
Expand Down Expand Up @@ -103,7 +103,7 @@
class="flex-grow-1 my-1 mx-2 overflow-hidden"
on:click={() => scrollToSpan(firstSpan)}
>
<div class="float-end labels">
<div class="float-end labels me-1">
{#each spans as span}
<span
on:mouseover={(ev) =>
Expand Down Expand Up @@ -144,7 +144,7 @@
class="flex-grow-1 my-1 mx-2 overflow-hidden"
on:click={() => scrollToRelation(relation)}
>
<div class="float-end labels">
<div class="float-end labels me-1">
<LabelBadge
annotation={relation}
{ajaxClient}
Expand Down
Loading

0 comments on commit 160abac

Please sign in to comment.