Skip to content

Commit

Permalink
Remove duplicate PosTag class
Browse files Browse the repository at this point in the history
  • Loading branch information
Gram21 committed Sep 19, 2023
1 parent 406977a commit d9b0abf
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/* Licensed under MIT 2021-2023. */
package edu.kit.kastel.mcse.ardoco.core.api.text;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
* This class represents all valid part-of-speech (pos) tags
*
*/
public enum POSTag {
//@formatter:off
Expand Down Expand Up @@ -77,4 +80,19 @@ public boolean isVerb() {
public boolean isNoun() {
return getTag().startsWith("NN");
}

@JsonValue
public String toValue() {
return getTag();
}

@JsonCreator
public static POSTag forValue(String value) throws IOException {
try {
return get(value);
} catch (IllegalArgumentException e) {
throw new IOException("Cannot deserialize PosTag");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

import org.eclipse.collections.api.list.ImmutableList;

import edu.kit.kastel.mcse.ardoco.core.api.text.*;
import edu.kit.kastel.mcse.ardoco.core.api.text.DependencyTag;
import edu.kit.kastel.mcse.ardoco.core.api.text.POSTag;
import edu.kit.kastel.mcse.ardoco.core.api.text.Phrase;
import edu.kit.kastel.mcse.ardoco.core.api.text.Sentence;
import edu.kit.kastel.mcse.ardoco.core.api.text.Text;
import edu.kit.kastel.mcse.ardoco.core.api.text.Word;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.IncomingDependencyDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.OutgoingDependencyDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.PosTag;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.SentenceDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.TextDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.WordDto;
Expand All @@ -27,7 +31,7 @@ public class ObjectToDtoConverter {

/**
* converts an ArDoCo text into a text DTO
*
*
* @param text the ArDoCo text
* @return the text DTO
*/
Expand Down Expand Up @@ -74,7 +78,7 @@ private WordDto convertToWordDTO(Word word) throws NotConvertableException {
wordDTO.setText(word.getText());
wordDTO.setLemma(word.getLemma());
try {
wordDTO.setPosTag(PosTag.forValue(word.getPosTag().toString()));
wordDTO.setPosTag(POSTag.forValue(word.getPosTag().toString()));
} catch (IOException e) {
throw new NotConvertableException(String.format("IOException when converting word with id %d to WordDto: PosTag not found.", wordDTO.getId()));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.util.List;
import java.util.Objects;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonProperty;

import edu.kit.kastel.mcse.ardoco.core.api.text.POSTag;

/**
* Definition of a word
Expand All @@ -17,7 +19,7 @@ public class WordDto {
private List<OutgoingDependencyDto> outgoingDependencies = new ArrayList<>();
private long sentenceNo;
private String text;
private PosTag posTag;
private POSTag posTag;

/**
* The id of the word. Should be ascending from 1 for the first word in the text.
Expand Down Expand Up @@ -72,12 +74,12 @@ public void setOutgoingDependencies(List<OutgoingDependencyDto> value) {
}

@JsonProperty("posTag")
public PosTag getPosTag() {
public POSTag getPosTag() {
return posTag;
}

@JsonProperty("posTag")
public void setPosTag(PosTag value) {
public void setPosTag(POSTag value) {
this.posTag = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

import org.eclipse.collections.api.factory.Lists;

import edu.kit.kastel.mcse.ardoco.core.api.text.*;
import edu.kit.kastel.mcse.ardoco.core.api.text.DependencyTag;
import edu.kit.kastel.mcse.ardoco.core.api.text.POSTag;
import edu.kit.kastel.mcse.ardoco.core.api.text.Phrase;
import edu.kit.kastel.mcse.ardoco.core.api.text.PhraseType;
import edu.kit.kastel.mcse.ardoco.core.api.text.Sentence;
import edu.kit.kastel.mcse.ardoco.core.api.text.Text;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.IncomingDependencyDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.OutgoingDependencyDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.PosTag;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.SentenceDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.TextDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.WordDto;
Expand All @@ -30,7 +34,7 @@ private TestUtil() {

/**
* generates a default textDTO without dependencies between the words
*
*
* @return a default textDTO
*/
public static TextDto generateDefaultDTO() throws IOException {
Expand All @@ -39,28 +43,28 @@ public static TextDto generateDefaultDTO() throws IOException {
word1.setSentenceNo(1);
word1.setLemma("this");
word1.setText("This");
word1.setPosTag(PosTag.forValue("DT"));
word1.setPosTag(POSTag.forValue("DT"));

WordDto word2 = new WordDto();
word2.setId(2);
word2.setSentenceNo(1);
word2.setLemma("be");
word2.setText("is");
word2.setPosTag(PosTag.forValue("VBZ"));
word2.setPosTag(POSTag.forValue("VBZ"));

WordDto word3 = new WordDto();
word3.setId(3);
word3.setSentenceNo(1);
word3.setLemma("I");
word3.setText("me");
word3.setPosTag(PosTag.forValue("PRP"));
word3.setPosTag(POSTag.forValue("PRP"));

WordDto word4 = new WordDto();
word4.setId(4);
word4.setSentenceNo(1);
word4.setLemma(".");
word4.setText(".");
word4.setPosTag(PosTag.forValue("."));
word4.setPosTag(POSTag.forValue("."));

List<WordDto> words = new ArrayList<>(List.of(word1, word2, word3, word4));

Expand All @@ -87,9 +91,9 @@ public static TextDto generateDefaultDTO() throws IOException {
public static Text generateDefaultText() {
TextImpl text = new TextImpl();
List<WordImpl> words = new ArrayList<>(List.of(new WordImpl(text, 0, 0, "This", POSTag.DETERMINER, "this", new ArrayList<>(), new ArrayList<>()),
new WordImpl(text, 1, 0, "is", POSTag.VERB_SINGULAR_PRESENT_THIRD_PERSON, "be", new ArrayList<>(), new ArrayList<>()), new WordImpl(text, 2, 0,
"me", POSTag.PRONOUN_PERSONAL, "I", new ArrayList<>(), new ArrayList<>()), new WordImpl(text, 3, 0, ".", POSTag.CLOSER, ".",
new ArrayList<>(), new ArrayList<>())));
new WordImpl(text, 1, 0, "is", POSTag.VERB_SINGULAR_PRESENT_THIRD_PERSON, "be", new ArrayList<>(), new ArrayList<>()),
new WordImpl(text, 2, 0, "me", POSTag.PRONOUN_PERSONAL, "I", new ArrayList<>(), new ArrayList<>()),
new WordImpl(text, 3, 0, ".", POSTag.CLOSER, ".", new ArrayList<>(), new ArrayList<>())));

SentenceImpl sentence1 = new SentenceImpl(0, "This is me.", Lists.immutable.ofAll(words));

Expand Down Expand Up @@ -126,28 +130,28 @@ public static TextDto generateDTOWithMultipleSentences() throws IOException {
word1.setSentenceNo(1);
word1.setLemma("this");
word1.setText("This");
word1.setPosTag(PosTag.forValue("DT"));
word1.setPosTag(POSTag.forValue("DT"));

WordDto word2 = new WordDto();
word2.setId(2);
word2.setSentenceNo(1);
word2.setLemma("be");
word2.setText("is");
word2.setPosTag(PosTag.forValue("VBZ"));
word2.setPosTag(POSTag.forValue("VBZ"));

WordDto word3 = new WordDto();
word3.setId(3);
word3.setSentenceNo(1);
word3.setLemma("I");
word3.setText("me");
word3.setPosTag(PosTag.forValue("PRP"));
word3.setPosTag(POSTag.forValue("PRP"));

WordDto word4 = new WordDto();
word4.setId(4);
word4.setSentenceNo(1);
word4.setLemma(".");
word4.setText(".");
word4.setPosTag(PosTag.forValue("."));
word4.setPosTag(POSTag.forValue("."));

List<WordDto> words = new ArrayList<>(List.of(word1, word2, word3, word4));

Expand All @@ -162,28 +166,28 @@ public static TextDto generateDTOWithMultipleSentences() throws IOException {
word5.setSentenceNo(2);
word5.setLemma("this");
word5.setText("This");
word5.setPosTag(PosTag.forValue("DT"));
word5.setPosTag(POSTag.forValue("DT"));

WordDto word6 = new WordDto();
word6.setId(6);
word6.setSentenceNo(2);
word6.setLemma("be");
word6.setText("is");
word6.setPosTag(PosTag.forValue("VBZ"));
word6.setPosTag(POSTag.forValue("VBZ"));

WordDto word7 = new WordDto();
word7.setId(7);
word7.setSentenceNo(2);
word7.setLemma("you");
word7.setText("you");
word7.setPosTag(PosTag.forValue("PRP"));
word7.setPosTag(POSTag.forValue("PRP"));

WordDto word8 = new WordDto();
word8.setId(8);
word8.setSentenceNo(2);
word8.setLemma(".");
word8.setText(".");
word8.setPosTag(PosTag.forValue("."));
word8.setPosTag(POSTag.forValue("."));

List<WordDto> words2 = new ArrayList<>(List.of(word5, word6, word7, word8));

Expand All @@ -203,9 +207,9 @@ public static Text generateTextWithMultipleSentences() {
List<Sentence> sentences = new ArrayList<>();

List<WordImpl> words = new ArrayList<>(List.of(new WordImpl(text, 0, 0, "This", POSTag.DETERMINER, "this", new ArrayList<>(), new ArrayList<>()),
new WordImpl(text, 1, 0, "is", POSTag.VERB_SINGULAR_PRESENT_THIRD_PERSON, "be", new ArrayList<>(), new ArrayList<>()), new WordImpl(text, 2, 0,
"me", POSTag.PRONOUN_PERSONAL, "I", new ArrayList<>(), new ArrayList<>()), new WordImpl(text, 3, 0, ".", POSTag.CLOSER, ".",
new ArrayList<>(), new ArrayList<>())));
new WordImpl(text, 1, 0, "is", POSTag.VERB_SINGULAR_PRESENT_THIRD_PERSON, "be", new ArrayList<>(), new ArrayList<>()),
new WordImpl(text, 2, 0, "me", POSTag.PRONOUN_PERSONAL, "I", new ArrayList<>(), new ArrayList<>()),
new WordImpl(text, 3, 0, ".", POSTag.CLOSER, ".", new ArrayList<>(), new ArrayList<>())));

SentenceImpl sentence1 = new SentenceImpl(0, "This is me.", Lists.immutable.ofAll(words));

Expand All @@ -222,9 +226,9 @@ public static Text generateTextWithMultipleSentences() {
sentences.add(sentence1);

List<WordImpl> words2 = new ArrayList<>(List.of(new WordImpl(text, 4, 1, "This", POSTag.DETERMINER, "this", new ArrayList<>(), new ArrayList<>()),
new WordImpl(text, 5, 1, "is", POSTag.VERB_SINGULAR_PRESENT_THIRD_PERSON, "be", new ArrayList<>(), new ArrayList<>()), new WordImpl(text, 6, 1,
"you", POSTag.PRONOUN_PERSONAL, "you", new ArrayList<>(), new ArrayList<>()), new WordImpl(text, 7, 1, ".", POSTag.CLOSER, ".",
new ArrayList<>(), new ArrayList<>())));
new WordImpl(text, 5, 1, "is", POSTag.VERB_SINGULAR_PRESENT_THIRD_PERSON, "be", new ArrayList<>(), new ArrayList<>()),
new WordImpl(text, 6, 1, "you", POSTag.PRONOUN_PERSONAL, "you", new ArrayList<>(), new ArrayList<>()),
new WordImpl(text, 7, 1, ".", POSTag.CLOSER, ".", new ArrayList<>(), new ArrayList<>())));
SentenceImpl sentence2 = new SentenceImpl(1, "This is you.", Lists.immutable.ofAll(words2));

Phrase subsubphrase2 = new PhraseImpl(Lists.immutable.of(words2.get(2)), PhraseType.NP, new ArrayList<>());
Expand Down Expand Up @@ -268,7 +272,7 @@ public static TextDto generateTextDtoWithDependencies() throws IOException {
word1.setSentenceNo(1);
word1.setLemma("hello");
word1.setText("Hello");
word1.setPosTag(PosTag.forValue("UH"));
word1.setPosTag(POSTag.forValue("UH"));
OutgoingDependencyDto outgoingDependency = new OutgoingDependencyDto();
outgoingDependency.setTargetWordId(2);
outgoingDependency.setDependencyTag(DependencyTag.PUNCT);
Expand All @@ -279,7 +283,7 @@ public static TextDto generateTextDtoWithDependencies() throws IOException {
word2.setSentenceNo(1);
word2.setLemma(".");
word2.setText(".");
word2.setPosTag(PosTag.forValue("."));
word2.setPosTag(POSTag.forValue("."));
IncomingDependencyDto incomingDependency = new IncomingDependencyDto();
incomingDependency.setSourceWordId(1);
incomingDependency.setDependencyTag(DependencyTag.PUNCT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.junit.jupiter.api.Test;

import edu.kit.kastel.mcse.ardoco.core.api.text.DependencyTag;
import edu.kit.kastel.mcse.ardoco.core.api.text.POSTag;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.IncomingDependencyDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.OutgoingDependencyDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.PosTag;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.SentenceDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.TextDto;
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.WordDto;
Expand Down Expand Up @@ -65,7 +65,7 @@ private TextDto getValidTextDtoExample() throws IOException {
expectedWord.setSentenceNo(1);
expectedWord.setLemma("hello");
expectedWord.setText("Hello");
expectedWord.setPosTag(PosTag.forValue("UH"));
expectedWord.setPosTag(POSTag.forValue("UH"));

OutgoingDependencyDto expectedOutDep = new OutgoingDependencyDto();
expectedOutDep.setTargetWordId(1);
Expand Down

0 comments on commit d9b0abf

Please sign in to comment.