Package net.sf.okapi.common.filters
Class InlineCodeFinder
- java.lang.Object
-
- net.sf.okapi.common.filters.InlineCodeFinder
-
public class InlineCodeFinder extends Object
Implements the methods needed to convert sections of a coded text into in-line codes.
-
-
Constructor Summary
Constructors Constructor Description InlineCodeFinder()Creates a new InlineCodeFinder object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRule(String pattern)Adds a new rule to the list.voidaddRules(Collection<String> rules)Adds a collection of rules to the list.InlineCodeFinderclone()Clones this finder.voidcompile()Compiles all the rules into a single compiled pattern.voidfromString(String data)Sets the options of this finder with the values stored in a given string.ArrayList<String>getRules()Gets a list of all rules.StringgetSample()Gets the sample text to go with the finder.voidprocess(Segment segment, boolean forceUniqueIds)voidprocess(TextFragment fragment)Applies the rules to a given content and converts all matching sections into in-line codes.voidreset()Resets this finder.voidsetSample(String value)Sets the sample text that can be used to check the rules in a regular expression editor.voidsetUseAllRulesWhenTesting(boolean value)Set the flag that indicates if all rules should be used when testing the patterns in a regular expression editor.StringtoString()Gets a string of all the options for this finder.booleanuseAllRulesWhenTesting()Indicates if all rules should be used when testing the patterns in a regular expression editor.
-
-
-
Field Detail
-
TAGTYPE
public static final String TAGTYPE
Type representing an inline code created with this class.- See Also:
- Constant Field Values
-
-
Method Detail
-
reset
public void reset()
Resets this finder.
-
clone
public InlineCodeFinder clone()
Clones this finder.
-
addRule
public void addRule(String pattern)
Adds a new rule to the list.- Parameters:
pattern- The regular expression pattern for the rule.
-
addRules
public void addRules(Collection<String> rules)
Adds a collection of rules to the list.- Parameters:
rules- The collection of rules to add
-
getRules
public ArrayList<String> getRules()
Gets a list of all rules.- Returns:
- The list of all rules.
-
getSample
public String getSample()
Gets the sample text to go with the finder.- Returns:
- The sample text.
-
setSample
public void setSample(String value)
Sets the sample text that can be used to check the rules in a regular expression editor.- Parameters:
value- The sample text.
-
useAllRulesWhenTesting
public boolean useAllRulesWhenTesting()
Indicates if all rules should be used when testing the patterns in a regular expression editor.- Returns:
- True if all rules should be used when testing, false when only the current rule should be used.
-
setUseAllRulesWhenTesting
public void setUseAllRulesWhenTesting(boolean value)
Set the flag that indicates if all rules should be used when testing the patterns in a regular expression editor.- Parameters:
value- True to use all rules, false to use only the current rule.
-
compile
public void compile()
Compiles all the rules into a single compiled pattern.- Throws:
PatternSyntaxException- When there is a syntax error in one of the rules.
-
process
public void process(TextFragment fragment)
Applies the rules to a given content and converts all matching sections into in-line codes. The new codes have the typeTAGTYPE.IMPORTANT: Note that the data of the original data in the new inline code may need to be escaped as they are now part of the fragment 'skeleton' and are not escaped back to the original format when merging.
- Parameters:
fragment- The fragment where to apply the rules.
-
process
public void process(Segment segment, boolean forceUniqueIds)
-
toString
public String toString()
Gets a string of all the options for this finder.- Overrides:
toStringin classObject- Returns:
- The string storing all the options for this finder.
- See Also:
fromString(String)
-
fromString
public void fromString(String data)
Sets the options of this finder with the values stored in a given string. The provided string can be created bytoString().- Parameters:
data- String storing all the options for this finder.- See Also:
toString()
-
-