Commit e0f2a999 authored by WUUUGI's avatar WUUUGI

Fixed ChunkLabels positioning.

parent 13d9c9b7
Pipeline #26479864 failed with stages
in 17 minutes and 44 seconds
......@@ -175,7 +175,6 @@ public class ChunkingBehavior extends AnnotationBehavior {
@Override
public Region getTokenTagsRegion() {
//TODO: return postagstream;
return posTagStream;
}
......@@ -235,7 +234,6 @@ public class ChunkingBehavior extends AnnotationBehavior {
followingTokens.addAll(JCasUtil.selectFollowing(jCas, Token.class, oldChunkTokens.get(oldChunkTokens.size() - 1), 1));
} else {
//<--
//TODO: If the switch between preceding and following should be corrected: Start here
followingTokens.addAll(JCasUtil.selectPreceding(jCas, Token.class, oldChunkTokens.get(0), 1));
}
......
......@@ -137,6 +137,7 @@ public class NamedEntityTaggingBehavior extends AnnotationBehavior {
@Override
public Selection suggestNewSelection(Selection oldSelection, Selection newSelection) {
newSelection = super.suggestNewSelection(oldSelection, newSelection);
if (newSelection == null || oldSelection == null) {
return null;
}
......
......@@ -294,7 +294,7 @@ public class JCasService {
return namedEntityTokens;
}
return asList();
return emptyList();
}
public void createNamedEntity(Selection selection, String namedEntityType) {
......
......@@ -53,40 +53,7 @@ public class TokenStream extends Region {
@Getter
private PaginationAdapter<TokenLabel, Token> tokenLabelAdapter = new PaginationAdapter<>(
() -> new TokenLabel(TokenLabel.VERTICAL_BAR_HEIGHT),
(TokenLabel tokenLabel, Token token) -> {
boolean showCircle = false;
boolean showVerticalBar = false;
if (token != null) {
if (jCas != null) {
Map<Token, Collection<Sentence>> tokenSentenceMap = JCasUtil.indexCovering(jCas, Token.class, Sentence.class);
Optional<Sentence> sentence = tokenSentenceMap.get(token)
.stream()
.findFirst();
showVerticalBar = sentence.isPresent() && sentence.get().getEnd() == token.getEnd();
if (token.getBegin() > 0) {
Token preceding = JCasUtil.selectSingleRelative(jCas, Token.class, token, -1);
showCircle = preceding != null && preceding.getEnd() == token.getBegin();
}
}
tokenLabel.setText(token.getText());
if (selection != null && selection.getSelectedSentenceTokens().contains(token)) {
tokenLabel.setColoring(Coloring.FOCUS);
}
if (selection != null && selection.getSelectedTokens().contains(token)) {
tokenLabel.setColoring(Coloring.MORE_FOCUS);
}
tokenLabel.setId("token-" + token.hashCode());
} else {
tokenLabel.setText(null);
tokenLabel.setColoring(Coloring.LESS_FOCUS);
tokenLabel.setId(null);
}
tokenLabel.showVerticalBar(showVerticalBar);
tokenLabel.showCircle(showCircle);
},
this::bind,
TokenLabel::fullWidthProperty
);
......@@ -104,6 +71,41 @@ public class TokenStream extends Region {
});
}
private void bind(TokenLabel tokenLabel, Token token) {
boolean showCircle = false;
boolean showVerticalBar = false;
if (token != null) {
if (jCas != null) {
Map<Token, Collection<Sentence>> tokenSentenceMap = JCasUtil.indexCovering(jCas, Token.class, Sentence.class);
Optional<Sentence> sentence = tokenSentenceMap.get(token)
.stream()
.findFirst();
showVerticalBar = sentence.isPresent() && sentence.get().getEnd() == token.getEnd();
if (token.getBegin() > 0) {
Token preceding = JCasUtil.selectSingleRelative(jCas, Token.class, token, -1);
showCircle = preceding != null && preceding.getEnd() == token.getBegin();
}
}
tokenLabel.setText(token.getText());
if (selection != null && selection.getSelectedSentenceTokens().contains(token)) {
tokenLabel.setColoring(Coloring.FOCUS);
}
if (selection != null && selection.getSelectedTokens().contains(token)) {
tokenLabel.setColoring(Coloring.MORE_FOCUS);
}
tokenLabel.setId("token-" + token.hashCode());
} else {
tokenLabel.setText(null);
tokenLabel.setColoring(Coloring.LESS_FOCUS);
tokenLabel.setId(null);
}
tokenLabel.showVerticalBar(showVerticalBar);
tokenLabel.showCircle(showCircle);
}
public void bindToSentences(ObservableList<Sentence> sentences) {
sentences.addListener((ListChangeListener<Sentence>) c -> {
if (jCas == null) {
......
......@@ -90,7 +90,7 @@ public class PaginationAdapter<R extends Region, V> implements ChangeListener<Nu
private List<PaginationAdapter<? extends Region, V>> childPaginationAdapters = new ArrayList<>();
public void addChildPaginationAdapter(PaginationAdapter<? extends Region, V> paginationAdapter) {
childPaginationAdapters.clear();
// TODO: If statement that checks if a paginationadapter already exists in childPaginationAdapters.
childPaginationAdapters.add(paginationAdapter);
}
......
......@@ -257,7 +257,6 @@ public class ChunkStream extends TaggingStream {
if (region == null) {
continue;
}
//TODO: There is a bug here, the width is always one REGION_DISTANCE too much
width += region.labelMinWidthProperty().getValue();
width += REGION_DISTANCE;
}
......
......@@ -10,7 +10,7 @@ package de.schrieveslaach.nlpf.qpt.view.control.streams;
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*0
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
......@@ -127,9 +127,12 @@ public class ChunkingBehaviorTest extends AnnotationBehaviorTest<ChunkingBehavio
public void shouldShowAlreadyAssignedChunk() {
loadJCasWithChunkAndSelectFirstToken();
moveSelectionDown();
moveSelectionUp();
moveSelectionToRight();
LabelSpinner<String> spinner = find("#spinner-25");
//TODO: FIX
assertThat(spinner.valueProperty().get(), is(equalTo("*")));
}
......@@ -238,6 +241,7 @@ public class ChunkingBehaviorTest extends AnnotationBehaviorTest<ChunkingBehavio
Chunk chunk = new Chunk(jCas, 6, 19);
chunk.setChunkValue("NP");
String chunkValue = chunk.getChunkValue();
chunk.addToIndexes();
interact(() -> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment