Search in sources :

Example 1 with TagInstance

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;
}
Also used : TagDefinition(de.catma.tag.TagDefinition) TagInstance(de.catma.tag.TagInstance) IDGenerator(de.catma.util.IDGenerator) Property(de.catma.tag.Property) Nodes(nu.xom.Nodes)

Example 2 with 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;
}
Also used : TagInstance(de.catma.tag.TagInstance) ArrayList(java.util.ArrayList) TagReference(de.catma.document.annotation.TagReference)

Example 3 with TagInstance

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;
}
Also used : TreeSet(java.util.TreeSet) TagInstance(de.catma.tag.TagInstance) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Property(de.catma.tag.Property)

Example 4 with 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;
}
Also used : TagInstance(de.catma.tag.TagInstance) ArrayList(java.util.ArrayList) TagReference(de.catma.document.annotation.TagReference) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Range(de.catma.document.Range)

Example 5 with TagInstance

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();
}
Also used : TagInstance(de.catma.tag.TagInstance)

Aggregations

TagInstance (de.catma.tag.TagInstance)23 Property (de.catma.tag.Property)17 TagDefinition (de.catma.tag.TagDefinition)15 TagReference (de.catma.document.annotation.TagReference)14 ArrayList (java.util.ArrayList)12 PropertyDefinition (de.catma.tag.PropertyDefinition)10 List (java.util.List)10 Range (de.catma.document.Range)8 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)8 TagsetDefinition (de.catma.tag.TagsetDefinition)8 SourceDocument (de.catma.document.source.SourceDocument)7 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)6 TagLibrary (de.catma.tag.TagLibrary)6 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)5 UI (com.vaadin.ui.UI)5 IDGenerator (de.catma.util.IDGenerator)5 Collection (java.util.Collection)5 Notification (com.vaadin.ui.Notification)4 Type (com.vaadin.ui.Notification.Type)4 Project (de.catma.project.Project)4