001package de.monochromata.anaphors.perspectivation; 002 003/** 004 * A perspectivation relative to an offset in a document. 005 * <p> 006 * Conceptually, perspectivation is a process that turns a conceptual/semantic 007 * representation into a textual representation - i.e. choosing words and 008 * syntactic structures to express meaning. This class represents rather 009 * low-level operations that are used during a perspectivation process to turn a 010 * document that contains a conceptual/semantic representation that could also 011 * be used as textual representation into a text optimized for human readers. 012 * <p> 013 * The offset of a perspectivation is relative to the offset of the positions it 014 * belongs to. Since positions in a document are updated when the document is 015 * changed, the perspectivation remains applicable even after document 016 * modifications. 017 * 018 * @see Underspecification 019 */ 020public abstract class Perspectivation { 021 022 public final int originOffsetRelativeToPositionOffset; 023 public final int length; 024 025 /** 026 * Used in contract testing. 027 */ 028 @SuppressWarnings("unused") 029 protected Perspectivation() { 030 originOffsetRelativeToPositionOffset = 0; 031 length = 0; 032 } 033 034 /** 035 * @param originOffsetRelativeToPositionOffset is relative to origin offsets 036 * because that does not require 037 * accounting for previously hidden 038 * regions. Must be {@code >= 0}. 039 */ 040 public Perspectivation(final int originOffsetRelativeToPositionOffset, final int length) { 041 assert originOffsetRelativeToPositionOffset >= 0 : "relative offset >= 0"; 042 assert length >= 0 : "length >= 0"; 043 this.originOffsetRelativeToPositionOffset = originOffsetRelativeToPositionOffset; 044 this.length = length; 045 } 046 047 @Override 048 public int hashCode() { 049 final int prime = 31; 050 int result = 1; 051 result = prime * result + length; 052 result = prime * result + originOffsetRelativeToPositionOffset; 053 return result; 054 } 055 056 @Override 057 public boolean equals(final Object obj) { 058 if (this == obj) { 059 return true; 060 } 061 if (obj == null) { 062 return false; 063 } 064 if (getClass() != obj.getClass()) { 065 return false; 066 } 067 final Perspectivation other = (Perspectivation) obj; 068 if (length != other.length) { 069 return false; 070 } 071 if (originOffsetRelativeToPositionOffset != other.originOffsetRelativeToPositionOffset) { 072 return false; 073 } 074 return true; 075 } 076 077 @Override 078 public String toString() { 079 return "Perspectivation [originOffsetRelativeToPositionOffset=" + originOffsetRelativeToPositionOffset 080 + ", length=" + length + "]"; 081 } 082 083 public static class Hide extends Perspectivation { 084 085 /** 086 * @param originOffsetRelativeToPositionOffset uses origin offsets because that 087 * makes it easier to hide further 088 * regions without needing to 089 * account for previously hidden 090 * regions 091 */ 092 public Hide(final int originOffsetRelativeToPositionOffset, final int length) { 093 super(originOffsetRelativeToPositionOffset, length); 094 } 095 096 @Override 097 public String toString() { 098 return "Hide [originOffsetRelativeToPositionOffset=" + originOffsetRelativeToPositionOffset + ", length=" 099 + length + "]"; 100 } 101 102 } 103 104 public static class ToLowerCase extends Perspectivation { 105 106 /** 107 * @param originOffsetRelativeToPositionOffset uses origin offsets because that 108 * does not require accounting for 109 * previously hidden regions 110 */ 111 public ToLowerCase(final int originOffsetRelativeToPositionOffset) { 112 super(originOffsetRelativeToPositionOffset, 1); 113 } 114 115 @Override 116 public String toString() { 117 return "ToLowerCase [originOffsetRelativeToPositionOffset=" + originOffsetRelativeToPositionOffset + "]"; 118 } 119 120 } 121 122}