
de.citec.tcs.alignment.adp.GlobalAsymmetricGrammar Maven / Gradle / Ivy
/*
* TCS Alignment Toolbox
*
* Copyright (C) 2013-2015
* Benjamin Paaßen, Georg Zentgraf
* AG Theoretical Computer Science
* Centre of Excellence Cognitive Interaction Technology (CITEC)
* University of Bielefeld
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package de.citec.tcs.alignment.adp;
import de.citec.tcs.alignment.adp.GlobalAsymmetricGrammar.Nonterminal;
import de.citec.tcs.alignment.comparators.OperationType;
import java.util.ArrayList;
import java.util.EnumSet;
/**
* This is a slight variation of the global alignment grammar.
* It enforces that deletions come before insertions and thereby limits the
* search space a little. It also prevents semantic ambiguity as described by
* Giegerich et al.
*
* Consider the two input sequences "a" and "b". The global alignment grammar
* then permits both these alignments:
*
* DELETION('a', INSERTION(end, 'b'))
* INSERTION(DELETION('a', end, 'b'))
*
* But these alignments are semantically equivalent. Therefore this grammar
* does not allow the second alignment but only the first.
*
* This does not come with any runtime advantage, because the management of the
* additional dynamic programming table comes with a higher cost than leaving
* the additional candidates in the search space. However this grammar might
* be interesting for derivative calculation as it changes the operations that
* are used and does not over-emphasize deletions and insertions in comparison
* to replacements.
*
* The GAP-L version of this grammar would be
*
* grammar gra_global_asym uses sig_alignment(axiom = ALI)
* {
*
* ALI = del(, ALI) |
* ins(, INS) |
* rep(, ALI) |
* nil() #h;
*
* INS = ins(, INS) |
* rep(, ALI) |
* nil() #h;
* }
*
* @author Benjamin Paassen - bpaassen(at)techfak.uni-bielefeld.de
*/
public class GlobalAsymmetricGrammar implements Grammar {
/**
* Creates an instance of the global, asymmetric grammar.
*/
public GlobalAsymmetricGrammar() {
}
/**
* {@inheritDoc}
*/
@Override
public Nonterminal[] dependencySort() {
return Nonterminal.values();
}
private final ProductionRule del
= new ProductionRule<>(OperationType.DELETION, Nonterminal.ALI);
private final ProductionRule ins
= new ProductionRule<>(OperationType.INSERTION, Nonterminal.ALI);
private final ProductionRule rep
= new ProductionRule<>(OperationType.REPLACEMENT, Nonterminal.ALI);
/**
* {@inheritDoc}
*/
@Override
public ArrayList> getPossibleRules(
Nonterminal nonterminal, int leftSize, int rightSize, int M, int N) {
final ArrayList> rules = new ArrayList<>();
if (leftSize > 0 && nonterminal == Nonterminal.ALI) {
rules.add(del);
}
if (rightSize > 0) {
rules.add(ins);
}
if (leftSize > 0 && rightSize > 0) {
rules.add(rep);
}
return rules;
}
/**
* {@inheritDoc}
*/
@Override
public boolean containsGaps() {
return true;
}
/**
* {@inheritDoc}
*/
@Override
public boolean containsSkips() {
return false;
}
/**
* {@inheritDoc}
*/
@Override
public Class getNonterminalClass() {
return Nonterminal.class;
}
/**
* {@inheritDoc}
*/
@Override
public Nonterminal getAxiom() {
return Nonterminal.ALI;
}
private final EnumSet accepting = EnumSet.allOf(Nonterminal.class);
/**
* {@inheritDoc}
*/
@Override
public EnumSet getAccepting() {
return accepting;
}
public static enum Nonterminal {
ALI,
INS
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy