001package de.monochromata.anaphors.ast.unify;
002
003import static de.monochromata.anaphors.ast.reference.strategy.concept.Hyponymy.Hy_KIND;
004import static de.monochromata.anaphors.ast.reference.strategy.concept.TypeRecurrence.Rt_KIND;
005import static de.monochromata.anaphors.ast.unify.Unification.haveEqualReferent;
006import static de.monochromata.anaphors.ast.unify.Unification.unifyListElements;
007
008import java.util.List;
009import java.util.function.BiPredicate;
010
011import de.monochromata.anaphors.ast.ASTBasedAnaphora;
012import de.monochromata.anaphors.ast.relatedexp.RelatedExpression;
013
014public interface TypeRecurrencePrecedesHyponymy {
015
016        static <N, E, T, B, TB extends B, S, I, QI, R extends RelatedExpression<N, T, B, TB, S, QI, R>, A extends ASTBasedAnaphora<N, E, T, B, TB, S, I, QI, R, A>> List<A> preferTypeRecurrenceOverHynonymy(
017                        final List<A> potentialAnaphoraRelations) {
018                return unifyListElements(potentialAnaphoraRelations, preferRtOverHy());
019        }
020
021        static <N, E, T, B, TB extends B, S, I, QI, R extends RelatedExpression<N, T, B, TB, S, QI, R>, A extends ASTBasedAnaphora<N, E, T, B, TB, S, I, QI, R, A>> BiPredicate<A, A> preferRtOverHy() {
022                return (anaphora1, anaphora2) -> haveRtAndHy(anaphora1, anaphora2) && haveEqualReferent(anaphora1, anaphora2);
023        }
024
025        private static <N, E, T, B, TB extends B, S, I, QI, R extends RelatedExpression<N, T, B, TB, S, QI, R>, A extends ASTBasedAnaphora<N, E, T, B, TB, S, I, QI, R, A>> boolean haveRtAndHy(
026                        final A anaphora1, final A anaphora2) {
027                return anaphora1.getReferentializationStrategy().getKind().equals(Rt_KIND)
028                                && anaphora2.getReferentializationStrategy().getKind().equals(Hy_KIND);
029        }
030
031}