<commit_before>package eu.modernmt.model;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;

/**
 * Created by davide on 17/02/16.
 */
public class Translation extends Sentence {

    protected final Sentence source;
    private Alignment alignment;
    private long elapsedTime;

    public Translation(Word[] words, Sentence source, Alignment alignment) {
        this(words, null, source, alignment);
    }

    public Translation(Word[] words, Tag[] tags, Sentence source, Alignment alignment) {
        super(words, tags);
        this.source = source;
        this.alignment = alignment;
        this.elapsedTime = 0;
    }

    public long getElapsedTime() {
        return elapsedTime;
    }

    public void setElapsedTime(long elapsedTime) {
        this.elapsedTime = elapsedTime;
    }

    public Sentence getSource() {
        return source;
    }

    public void setAlignment(Alignment alignment) {
        this.alignment = alignment;
    }

    public Alignment getAlignment() {
        return alignment;
    }

    public boolean hasAlignment() {
        return alignment != null && alignment.size() > 0;
    }

    public List<Phrase> getPhrases() {
        Word[] sourceWords = source.getWords();

        ArrayList<Phrase> phrases = new ArrayList<>();
        BitSet coveredInSource = new BitSet(sourceWords.length);
        BitSet coveredInTarget = new BitSet(words.length);

        BitSet coveredPerPhraseInSource = new BitSet(sourceWords.length);
        BitSet coveredPerPhraseInTarget = new BitSet(words.length);<commit_msg>Translation.getPhrases() returns singleton list with translation itself if alignment is missing.<commit_after>package eu.modernmt.model;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.List;

/**
 * Created by davide on 17/02/16.
 */
public class Translation extends Sentence {

    protected final Sentence source;
    private Alignment alignment;
    private long elapsedTime;

    public Translation(Word[] words, Sentence source, Alignment alignment) {
        this(words, null, source, alignment);
    }

    public Translation(Word[] words, Tag[] tags, Sentence source, Alignment alignment) {
        super(words, tags);
        this.source = source;
        this.alignment = alignment;
        this.elapsedTime = 0;
    }

    public long getElapsedTime() {
        return elapsedTime;
    }

    public void setElapsedTime(long elapsedTime) {
        this.elapsedTime = elapsedTime;
    }

    public Sentence getSource() {
        return source;
    }

    public void setAlignment(Alignment alignment) {
        this.alignment = alignment;
    }

    public Alignment getAlignment() {
        return alignment;
    }

    public boolean hasAlignment() {
        return alignment != null && alignment.size() > 0;
    }

    public List<Phrase> getPhrases() {
        if (!hasAlignment())
            return Collections.singletonList(new Phrase(0, this.source.getWords(), words));

        Word[] sourceWords = source.getWords();

        ArrayList<Phrase> phrases = new ArrayList<>();
        BitSet coveredInSource = new BitSet(sourceWords.length);
        BitSet coveredInTarget = new BitSet(words.length);

        BitSet coveredPerPhraseInSource = new BitSet(sourceWords.length);
        BitSet coveredPerPhraseInTarget = new BitSet(words.length);
{'fraction_non_alphanumeric': 0.09436744323208493, 'fraction_numerical': 0.005013270421704512, 'mean_word_length': 2.9350348027842226, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1460274', 'n_tokens_mistral': 981, 'n_tokens_neox': 895, 'n_words': 252}