Skip to content

Commit

Permalink
Update v2.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dwerning committed Aug 12, 2024
1 parent 9743b72 commit b5b88ba
Show file tree
Hide file tree
Showing 18 changed files with 474 additions and 433 deletions.
10 changes: 8 additions & 2 deletions src/main/java/tla/backend/api/ApiController.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package tla.backend.api;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import tla.backend.es.model.Metadata;
import tla.backend.es.repo.LemmaRepo;
import tla.backend.service.MetadataService;
import tla.backend.api.LemmaController;


@RestController
@RequestMapping("/")
Expand All @@ -36,7 +43,7 @@ public class ApiController {
public ResponseEntity<String> listEndpoints() {
return new ResponseEntity<>(
String.join(
"\n",
"<br/>",
handlerMapping.getHandlerMethods().keySet().stream().flatMap(
mapping -> mapping.getPatternValues().stream()
).sorted().collect(
Expand Down Expand Up @@ -72,5 +79,4 @@ public ResponseEntity<?> getVersionInfo() throws IOException {
statusCode
);
}

}
18 changes: 17 additions & 1 deletion src/main/java/tla/backend/api/EntityController.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,23 @@ public ResponseEntity<SingleDocumentWrapper<? extends AbstractDto>> get(@PathVar
log.error("could not find entity {}", id);
throw new ObjectNotFoundException(id, this.getService().getModelClass().getSimpleName());
}



/**
* Returns a //TODO a single document and all documents it references.
*/
public Boolean existsById(String id) {
Boolean result = false;
result = getService().existsById(id);
return result;
}

/**
* Returns the path of the service.
*/
public String getPath() {
return this.getService().getModelPath();
}

@CrossOrigin
@RequestMapping(
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/tla/backend/api/TokenController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tla.backend.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import tla.backend.es.model.SentenceEntity;
import tla.backend.service.EntityService;
import tla.backend.service.TokenService;
import tla.domain.dto.SentenceDto;

@RestController
public class TokenController extends EntityController<SentenceEntity, SentenceDto> {

@Autowired
private TokenService service;

@Override
public EntityService<SentenceEntity, ?, SentenceDto> getService() {
return this.service;
}

}
74 changes: 74 additions & 0 deletions src/main/java/tla/backend/api/TypeOfIdController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package tla.backend.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;


@RestController
@RequestMapping("/typeofid")
public class TypeOfIdController {

//Controller Beginn
@Autowired
private LemmaController lemmaController;

@Autowired
private SentenceController sentenceController;

@Autowired
private TextController textController;

@Autowired
private CorpusObjectController corpusObjectController;

@Autowired
private ThesaurusController thesaurusController;

@Autowired
private TokenController tokenController;
//Controller Ende

@Autowired
private RequestMappingHandlerMapping handlerMapping;

/**
* checks if id exists and returns index name
*/
@RequestMapping(
value = "/{id}",
method = RequestMethod.GET,
consumes = MediaType.ALL_VALUE,
produces = MediaType.ALL_VALUE
)
public ResponseEntity<String> getTypeOfId(@PathVariable String id){
//TODO List of Controller aus Vererbung
EntityController [] controllers = {
lemmaController,
sentenceController,
textController,
corpusObjectController,
thesaurusController,
tokenController
};
for(EntityController controller : controllers) {
System.out.println(controller.existsById(id));
if(controller.existsById(id)) {
return new ResponseEntity<String>(
controller.getPath(),
HttpStatus.OK
);
}
}
return new ResponseEntity<String>(
"false",
HttpStatus.OK
);
}
}
4 changes: 2 additions & 2 deletions src/main/java/tla/backend/es/model/LemmaEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public class LemmaEntity extends TLAEntity {
@JsonAlias({"time_span"})
private TimeSpan timeSpan;

@Field(type = FieldType.Keyword)
private Integer attestedSentencesCount;
@Field(type = FieldType.Integer)
private int attestedSentencesCount;

@Singular
@Field(type = FieldType.Object)
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/tla/backend/es/model/TextObjectEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package tla.backend.es.model;

import java.util.List;

import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Setting;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import tla.backend.es.model.meta.Recursable;
import tla.backend.es.model.meta.UserFriendlyEntity;
import tla.backend.es.model.parts.ObjectPath;
import tla.backend.es.model.parts.Translations;
import tla.domain.dto.TextDto;
import tla.domain.model.meta.BTSeClass;
import tla.domain.model.meta.TLADTO;

/**
* Text and Subtext model
*/
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@BTSeClass("BTSText")
@TLADTO(TextDto.class)
@Document(indexName = "text")
@Setting(settingPath = "/elasticsearch/settings/indices/text.json")
public class TextObjectEntity extends UserFriendlyEntity implements Recursable {

@Field(type = FieldType.Search_As_You_Type, name = "hash")
private String SUID;

@Field(type = FieldType.Keyword)
private String corpus;

@Field(type = FieldType.Object)
private ObjectPath[] paths;

@Field(type = FieldType.Object)
private List<Translations> translations;

@Field(type = FieldType.Object)
private WordCount wordCount;

@Getter
@Setter
@NoArgsConstructor
public static class WordCount {
@Field(type = FieldType.Integer)
int min = 0;
@Field(type = FieldType.Integer)
int max = 0;
/**
* for compatibility
*/
public WordCount(int count) {
this.min = count;
this.max = count;
}
}

}
60 changes: 0 additions & 60 deletions src/main/java/tla/backend/es/model/ThsEntryEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,69 +60,9 @@ public class ThsEntryEntity extends UserFriendlyEntity implements Recursable {
@Field(type = FieldType.Search_As_You_Type, name = "hash")
private String SUID;

@Field(type = FieldType.Object)
private Translations translations;

@Field(type = FieldType.Object)
private ObjectPath[] paths;

/**
* Returns translations of a thesaurus entry's label. If no explicit translations exist, this method
* attempts to extract translations from the <code>synonym_group</code> field of the passport.
*/
public Translations getTranslations() {
if (this.translations != null) {
return this.translations;
} else {
return this.extractTranslationsFromPassport();
}
}

/**
* Convert multilingual synonyms extracted from passport to {@link Translations} object.
*
* @return {@link Translations} instance or <code>null</code> if no synonyms are in passport
*/
private Translations extractTranslationsFromPassport() {
Translations res = null;
if (this.getPassport() != null) {
List<Passport> nodes = this.getPassport().extractProperty(
SYNONYMS_PASSPORT_PATH
);
Map<String, List<String>> synonyms = new HashMap<>();
nodes.stream().filter(
n -> n.containsKey(SYNONYM_LANG_PATH) && n.containsKey(SYNONYM_VALUE_PATH)
).forEach(
n -> {
List<String> translations = n.extractProperty(SYNONYM_VALUE_PATH).stream().map(
leafNode -> leafNode.getLeafNodeValue()
).collect(
Collectors.toList()
);
n.extractProperty(SYNONYM_LANG_PATH).forEach(
langValueNode -> {
String lang = langValueNode.getLeafNodeValue();
if (synonyms.containsKey(lang)) {
synonyms.get(lang).addAll(translations);
} else {
synonyms.put(lang, new ArrayList<String>(translations));
}
}
);
}
);
try {
res = objectMapper.readValue(
objectMapper.writeValueAsString(synonyms),
Translations.class
);
} catch (Exception e) {
log.error("something went wrong during synonum extraction", e);
}
}
return res;
}

/**
* Returns the timespan represented by a thesaurus entry in the form of a list
* of size 2 containing first and last year.
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/tla/backend/es/model/meta/ModelConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ protected static ModelMapper initModelMapper() {
LemmaEntity::getRevisionState, LemmaDto::setReviewState
);
modelMapper.createTypeMap(ThsEntryEntity.class, ThsEntryDto.class)
.addMappings(
m -> m.using(translationsToMapConverter).map(
ThsEntryEntity::getTranslations, ThsEntryDto::setTranslations
)
).addMapping(
.addMapping(
ThsEntryEntity::getRevisionState, ThsEntryDto::setReviewState
);
modelMapper.createTypeMap(TextEntity.class, TextDto.class)
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/tla/backend/es/query/ESQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import static org.elasticsearch.index.query.QueryBuilders.idsQuery;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
Expand Down Expand Up @@ -42,7 +44,22 @@ public ESQueryBuilder() {
this.nativeAggregationBuilders = new LinkedList<>();
this.dependencies = new LinkedList<>();
}

static final Map<String, String> criterias;
static { criterias = new HashMap<String, String>();
criterias.put("timeSpan.begin_asc", "timeSpan.end_asc");
criterias.put("timeSpan.begin_desc","timeSpan.end_desc");
criterias.put("timeSpan.end_asc", "timeSpan.begin_asc");
criterias.put("timeSpan.end_desc", "timeSpan.begin_desc");
//TODO Sortierkriterien vom Frontend mappen und nicht direkt auf ES zugreifen lassen
//TODO Mapping for other criterias sortKey,attestedSentenceCounts
};

public void setTimeSpanCriterias(String criteria) {
if(criterias.containsKey(criteria)) {
this.sortSpec.addSortingByString(criterias.get(criteria));
}
}

/**
* Put together an actual Elasticsearch query ready for execution.
*/
Expand Down
Loading

0 comments on commit b5b88ba

Please sign in to comment.