Skip to content

Commit

Permalink
Merge branch 'master' into tla-web-ButtonsTextSentencesFinal_CV_13Sept23
Browse files Browse the repository at this point in the history
  • Loading branch information
cvertan authored Sep 14, 2023
2 parents 9d19da3 + c5d3098 commit e05020d
Show file tree
Hide file tree
Showing 13 changed files with 390 additions and 136 deletions.
42 changes: 42 additions & 0 deletions src/main/java/tla/web/model/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package tla.web.model;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import tla.domain.dto.CommentDto;
import tla.domain.model.Passport;
import tla.domain.model.meta.BTSeClass;
import tla.domain.model.meta.TLADTO;
import tla.web.model.mappings.Util;
import tla.web.model.meta.BTSObject;

@Getter
@Setter
@NoArgsConstructor
@BTSeClass("BTSComment")
@TLADTO(CommentDto.class)
public class Comment extends BTSObject {

@Getter(AccessLevel.NONE)
private String body;

/**
* Escape markup before returning value.
*/
@Override
public String getName() {
return Util.escapeMarkup(super.getName());
}

public String getBody() {
//return this.body;
return Util.escapeMarkup(this.body);
}

}
48 changes: 21 additions & 27 deletions src/main/java/tla/web/model/CorpusObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,16 @@ public class CorpusObject extends BTSObject implements Hierarchic {

public static final String PASSPORT_PROP_DATE = "date.date.date";
@Setter(AccessLevel.NONE)
private List<String> date;

public List<String> getDate() {
if (this.date == null) {
this.date = extractDate(this);
}
return this.date;
}

private static List<String> extractDate(CorpusObject corpusobj) {
List<String> dates = new ArrayList<String>();
try {

List<Passport> datesPassport =corpusobj.getPassport().extractProperty(PASSPORT_PROP_DATE);

for(int i=0;i<datesPassport.size();i++) {
for(int j=0;j<datesPassport.get(i).extractObjectReferences().size();j++) {
private List<ObjectReference> date;
public List<ObjectReference> getDate(){
if (this.date == null) {
Passport passport;
this.date = this.extractObjectReferences(this,PASSPORT_PROP_DATE);
}
tla.domain.util.IO.json(this.date);
return this.date;
}

dates.add(datesPassport.get(i).extractObjectReferences().get(j).getName());
}
}

} catch (Exception e) {
System.out.println("INFO: Could not extract date from object "+corpusobj.getId());
}
return dates;
}

// Text object date comment

Expand Down Expand Up @@ -165,7 +148,7 @@ public List<String> getBibliography() {
* @param corpusobj The corpus object instance from whose passport the bibliography is to be extracted.
* @return List of textual bibliographic references or an empty list
*/
private static List<String> extractBibliography(CorpusObject corpusobj) {
protected static List<String> extractBibliography(CorpusObject corpusobj) {
List<String> bibliography = new ArrayList<>();
try {
corpusobj.getPassport().extractProperty(
Expand Down Expand Up @@ -268,6 +251,17 @@ public static ObjectReference extractObjectReference(Passport passport) {
return object;
}

private static List<ObjectReference> extractObjectReferences(CorpusObject object, String searchString) {
List<ObjectReference> objectReferences = new ArrayList();
try {
List<Passport> pass= object.getPassport().extractProperty(searchString);
pass.forEach(node -> objectReferences.add(node.extractObjectReferences().get(0)));
} catch (Exception e) {
System.out.println("could not extract language from text {} " + object.getId());
}
return objectReferences;
}

@Getter
public static class Place{
public Place(Passport passport) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/tla/web/model/Sentence.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,38 @@ public boolean isArtificiallyAligned() {
token -> token.getGlyphs().isMdcArtificiallyAligned() == true
);
}

public boolean hasComment() {
if (this.getRelations() == null)
return false;
if (!this.getRelations().containsKey("contains"))
return false;

List<ObjectReference> objReferences;
objReferences = this.getRelations().get("contains");

return objReferences.stream().anyMatch( // for at least one reference:
relationItem -> relationItem.getEclass().equals("BTSComment")
);
}

public boolean hasAnnotation() {
if (this.getRelations() == null)
return false;
if (!this.getRelations().containsKey("contains"))
return false;

List<ObjectReference> objReferences;
objReferences = this.getRelations().get("contains");
/*objReferences.stream().forEach(
token -> System.out.println(token.getEclass())
);*/

return objReferences.stream().anyMatch( // for at least one reference:
relationItem -> (relationItem.getEclass().equals("BTSAnnotation") && (relationItem.getType() == null || !relationItem.getType().equals("rubrum")))
);
}

public String getName() {
return this.getText() != null ? this.getText().getName() : null;
}
Expand Down
Loading

0 comments on commit e05020d

Please sign in to comment.