void TransfererRunner::putTargetForm_(Lattice& lattice, Lattice::EdgeDescriptor edge, zvalue surf) {

    // could be a form or a token
    bool isForm = ZPAIRP(surf);

    std::string category =
        (isForm ? zvalue_to_string(ZPAIRC(surf)->getSecond()) : "T");

    zvalue text =
        (isForm ? ZPAIRC(surf)->getFirst() : surf);

    LayerTagCollection tags =
        lattice.getLayerTagManager().createTagCollection(
            isForm ? targetFormTags_ : targetTokenTags_);

    AnnotationItem annotationItem(category, StringFrag(zvalue_to_string(text)));

    lattice.getAnnotationItemManager().setValue(
        annotationItem, "SurfacePosition", formsCounter_++);

    Lattice::EdgeSequence::Builder builder(lattice);
    builder.addEdge(edge);

    Lattice::VertexDescriptor fromVertex = lattice.getEdgeSource(edge);
    Lattice::VertexDescriptor toVertex = lattice.getEdgeTarget(edge);

    lattice.addEdge(
        fromVertex,
        toVertex,
        annotationItem,
        tags,
        builder.build());
}
Example #2
0
void RuleMatcher::addPosEdges(Lattice &lattice) {
    LayerTagMask mask = lattice.getLayerTagManager().getMask(
            lattice.getLayerTagManager().
            createSingletonTagCollection("form")
            );

    std::multimap<Lattice::VertexDescriptor, std::string> posEdgesMap;
    Lattice::EdgesSortedBySourceIterator edgeIterator =
        lattice.edgesSortedBySource(mask);
    while (edgeIterator.hasNext()) {
        Lattice::EdgeDescriptor edge = edgeIterator.next();
        int start = lattice.getEdgeBeginIndex(edge);
        int end = start + lattice.getEdgeLength(edge);
        AnnotationItem annotationItem = lattice.getEdgeAnnotationItem(edge);
        if (lattice::isDiscarded(lattice, edge))
            continue; //skip discarded forms
        std::string partOfSpeech = lattice::getPartOfSpeech(lattice, edge);
        std::pair<
            std::multimap<Lattice::VertexDescriptor, std::string>::iterator,
            std::multimap<Lattice::VertexDescriptor, std::string>::iterator
                > posEdgesMapIt =
                posEdgesMap.equal_range(start);
        bool alreadyAdded = false;
        if (posEdgesMapIt.first != posEdgesMapIt.second) {
            while (posEdgesMapIt.first != posEdgesMapIt.second) {
                if (posEdgesMapIt.first->second ==
                        partOfSpeech) {
                    alreadyAdded = true;
                    break;
                }
                posEdgesMapIt.first ++;
            }
        }
        if (! alreadyAdded) {
            AnnotationItem ai(partOfSpeech);
            lattice.getAnnotationItemManager().setValue(ai, "discard", "0");
            lattice.getAnnotationItemManager().setValue(ai, "head", "0");
            Lattice::EdgeSequence::Builder seqBuilder(lattice);
            seqBuilder.addEdge(edge);
            lattice.addEdge(
                    start,
                    end,
                    ai,
                    lattice.getLayerTagManager().
                    createSingletonTagCollection("parse"),
                    seqBuilder.build()
                    );
            posEdgesMap.insert(std::pair< Lattice::VertexDescriptor, std::string>(
                        start, partOfSpeech));
        }
    }
}