use of de.catma.tag.TagInstance in project catma by forTEXT.
the class TeiUserMarkupCollectionDeserializer method createTagInstance.
private TagInstance createTagInstance(String tagInstanceID) {
TeiElement tagInstanceElement = teiDocument.getElementByID(tagInstanceID);
TagDefinition tagDefinition = tagLibrary.getTagDefinition(tagInstanceElement.getAttributeValue(Attribute.type));
if (!old2newTagInstanceIDs.containsKey(tagInstanceElement.getID())) {
old2newTagInstanceIDs.put(tagInstanceElement.getID(), new IDGenerator().generate());
}
final TagInstance tagInstance = new TagInstance(old2newTagInstanceIDs.get(tagInstanceElement.getID()), tagDefinition.getUuid(), tagDefinition.getAuthor(), ZonedDateTime.now().format(DateTimeFormatter.ofPattern(Version.DATETIMEPATTERN)), tagDefinition.getUserDefinedPropertyDefinitions(), tagDefinition.getTagsetDefinitionUuid());
Nodes systemPropertyElements = tagInstanceElement.getChildNodes(TeiElementName.f, AttributeValue.f_name_catma_system_property.getStartsWithFilter());
addProperties(tagDefinition, new AddPropertyHandler() {
public void addProperty(Property property) {
tagInstance.addSystemProperty(property);
}
}, systemPropertyElements);
Nodes userDefinedPropertyElements = tagInstanceElement.getChildNodes(TeiElementName.f, AttributeValue.f_name_catma_system_property.getNotStartsWithFilter());
addProperties(tagDefinition, new AddPropertyHandler() {
public void addProperty(Property property) {
tagInstance.addUserDefinedProperty(property);
}
}, userDefinedPropertyElements);
return tagInstance;
}
use of de.catma.tag.TagInstance in project catma by forTEXT.
the class TeiUserMarkupCollectionSerializer method writeSegment.
private TeiElement writeSegment(List<TagReference> tagReferences, TeiElement abElement, TeiElement textElement, Set<String> addedTagInstances, TagLibrary tagLibrary) {
List<TagInstance> tagInstances = new ArrayList<TagInstance>();
for (TagReference tr : tagReferences) {
if (!addedTagInstances.contains(tr.getTagInstanceId())) {
writeTagInstance(tr.getTagInstance(), textElement, tagLibrary);
addedTagInstances.add(tr.getTagInstanceId());
}
tagInstances.add(tr.getTagInstance());
}
AnaValueHandler anaValueHandler = new AnaValueHandler();
TeiElement seg = new TeiElement(TeiElementName.seg);
seg.setAttributeValue(Attribute.ana, anaValueHandler.makeValueFrom(tagInstances));
abElement.appendChild(seg);
return seg;
}
use of de.catma.tag.TagInstance in project catma by forTEXT.
the class JsonLdWebAnnotation method getTagInstance.
public TagInstance getTagInstance() throws Exception {
TagInstance tagInstance = new TagInstance(this.getTagInstanceUuid(), getBody().getTag().substring(getBody().getTag().lastIndexOf('/') + 1), // author gets redefined with the system properties below
"", ZonedDateTime.now().format(DateTimeFormatter.ofPattern(Version.DATETIMEPATTERN)), // these get added with the user defined properties below
Collections.emptyList(), getBody().getTagset().substring(getBody().getTagset().lastIndexOf('/') + 1));
TreeMap<String, TreeMap<String, TreeSet<String>>> properties = this.body.getProperties();
for (Map.Entry<String, TreeMap<String, TreeSet<String>>> entry : properties.entrySet()) {
for (Map.Entry<String, TreeSet<String>> subEntry : entry.getValue().entrySet()) {
Property property = new Property(subEntry.getKey(), subEntry.getValue());
if (entry.getKey().equals(JsonLdWebAnnotationBody_Dataset.SYSTEM_PROPERTIES_KEY)) {
tagInstance.addSystemProperty(property);
} else {
tagInstance.addUserDefinedProperty(property);
}
}
}
return tagInstance;
}
use of de.catma.tag.TagInstance in project catma by forTEXT.
the class JsonLdWebAnnotation method toTagReferenceList.
public List<TagReference> toTagReferenceList(String projectId, String markupCollectionId) throws Exception {
TagInstance tagInstance = this.getTagInstance();
String sourceDocumentUri = this.getSourceDocumentUri();
List<Range> ranges = this.getRanges();
List<TagReference> tagReferences = new ArrayList<>();
try {
for (Range range : ranges) {
tagReferences.add(new TagReference(tagInstance, sourceDocumentUri, range, markupCollectionId));
}
} catch (URISyntaxException e) {
throw new IOException(String.format("error loading Collection %1$s of project %2$s ", markupCollectionId, projectId), e);
}
return tagReferences;
}
use of de.catma.tag.TagInstance in project catma by forTEXT.
the class AnaValueHandler method makeValueFrom.
/**
* Creates a value string with an existent value string and
* a new reference to the given Tag.
* @param anaValue the existent value string
* @param tag the Tag we want to reference
* @return the new value string
*/
// public String makeValueFrom( String anaValue, Tag tag ) {
// StringBuilder builder = new StringBuilder( anaValue );
// if( !anaValue.equals( "" ) ) {
// builder.append( " " );
// }
// builder.append( "#" );
// builder.append( tag.getID() );
// return builder.toString();
// }
//
/**
* Creates a value string with references to the Tags in the given list.
* @param tags the tags we want to reference
* @return the new value string
*/
// public String makeValueFrom( List<Tag> tags ) {
// return makeValueFrom( tags.toArray( new Tag[]{} ) );
// }
public String makeValueFrom(List<TagInstance> tagInstances) {
StringBuilder builder = new StringBuilder();
String conc = "";
for (TagInstance tagInstance : tagInstances) {
builder.append(conc);
builder.append("#");
builder.append(tagInstance.getUuid());
conc = " ";
}
return builder.toString();
}
Aggregations