Class Prose
- java.lang.Object
-
- com.globalmentor.text.Prose
-
public class Prose extends java.lang.Object
Constants and utilities for working with the structure of text.Work in progress.
- Author:
- Garret Wilson
-
-
Field Summary
Fields Modifier and Type Field Description static int
ACT_HEADING
static int
AFTERWORD_HEADING
static int
ARTICLE_HEADING
static int
BIBLIOGRAPHY_HEADING
static int
BOOK_HEADING
static int
CHAPTER_HEADING
static int
CONTENTS_HEADING
static int
FOREWORD_HEADING
static int
GLOSSARY_HEADING
static int
GOSPEL_HEADING
static int
INDEX_HEADING
static int
INTRODUCTION_HEADING
static int
MAX_HEADING
The ordered heading with the highest value.static int
MAX_SIGNIFICANT_HEADING
The significant ordered heading with the highest value.static int
NO_HEADING
Indicates no heading.static int
PAGE_BREAK_HEADING
static int
PART_HEADING
static int
PREFACE_HEADING
static int
SCENE_HEADING
static int
SUB_HEADING
static int
TITLE_HEADING
static int
VOLUME_HEADING
-
Constructor Summary
Constructors Constructor Description Prose()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
containsOnlyIgnoreCase(java.lang.String text, java.lang.String[] requiredLabels, java.lang.String[] optionalLabels)
Determines if the given line contains several required and optional labels, compared without case sensitivity.static boolean
containsTitleLabel(java.lang.String text, java.lang.String label)
Determines if the given line contains a title label.static int
getHeadingType(java.lang.String text)
Checks to see which type of heading is represented by the given text.static int
getSectionNumber(java.lang.String text, java.lang.String sectionLabel)
Determines whether the given text is a numbered section heading, based upon the specified heading label.static boolean
isBreak(java.lang.String text)
Determines if the given text is a page break.static boolean
isPageNumber(java.lang.String text)
Determines if the given text is a page number.static boolean
isQuoted(java.lang.String string)
Determines if the given string is quoted.static boolean
isSubHeading(java.lang.String text)
Determines if the given text is a subheading.static boolean
isTitleCapitalizationRequired(java.lang.String word)
Determines if the given string should be capitalized if appearing in a title.static boolean
isTitleHeading(java.lang.String text)
Determines if the given text is a title heading.
-
-
-
Field Detail
-
NO_HEADING
public static final int NO_HEADING
Indicates no heading.- See Also:
- Constant Field Values
-
VOLUME_HEADING
public static final int VOLUME_HEADING
- See Also:
- Constant Field Values
-
BOOK_HEADING
public static final int BOOK_HEADING
- See Also:
- Constant Field Values
-
PART_HEADING
public static final int PART_HEADING
- See Also:
- Constant Field Values
-
CHAPTER_HEADING
public static final int CHAPTER_HEADING
- See Also:
- Constant Field Values
-
ACT_HEADING
public static final int ACT_HEADING
- See Also:
- Constant Field Values
-
SCENE_HEADING
public static final int SCENE_HEADING
- See Also:
- Constant Field Values
-
ARTICLE_HEADING
public static final int ARTICLE_HEADING
- See Also:
- Constant Field Values
-
SUB_HEADING
public static final int SUB_HEADING
- See Also:
- Constant Field Values
-
TITLE_HEADING
public static final int TITLE_HEADING
- See Also:
- Constant Field Values
-
MAX_SIGNIFICANT_HEADING
public static final int MAX_SIGNIFICANT_HEADING
The significant ordered heading with the highest value.- See Also:
- Constant Field Values
-
MAX_HEADING
public static final int MAX_HEADING
The ordered heading with the highest value.- See Also:
- Constant Field Values
-
CONTENTS_HEADING
public static final int CONTENTS_HEADING
- See Also:
- Constant Field Values
-
PREFACE_HEADING
public static final int PREFACE_HEADING
- See Also:
- Constant Field Values
-
FOREWORD_HEADING
public static final int FOREWORD_HEADING
- See Also:
- Constant Field Values
-
INTRODUCTION_HEADING
public static final int INTRODUCTION_HEADING
- See Also:
- Constant Field Values
-
AFTERWORD_HEADING
public static final int AFTERWORD_HEADING
- See Also:
- Constant Field Values
-
BIBLIOGRAPHY_HEADING
public static final int BIBLIOGRAPHY_HEADING
- See Also:
- Constant Field Values
-
GLOSSARY_HEADING
public static final int GLOSSARY_HEADING
- See Also:
- Constant Field Values
-
INDEX_HEADING
public static final int INDEX_HEADING
- See Also:
- Constant Field Values
-
GOSPEL_HEADING
public static final int GOSPEL_HEADING
- See Also:
- Constant Field Values
-
PAGE_BREAK_HEADING
public static final int PAGE_BREAK_HEADING
- See Also:
- Constant Field Values
-
-
Method Detail
-
getHeadingType
public static int getHeadingType(java.lang.String text)
Checks to see which type of heading is represented by the given text.The following types of headings are checked as numbered sections:
VOLUME_HEADING
BOOK_HEADING
ARTICLE_HEADING
PART_HEADING
CHAPTER_HEADING
ACT_HEADING
SCENE_HEADING
The following types of headings are checked by the presence of title labels:
CONTENTS_HEADING
PREFACE_HEADING
FOREWORD_HEADING
INTRODUCTION_HEADING
AFTERWORD_HEADING
BIBLIOGRAPHY_HEADING
GLOSSARY_HEADING
INDEX_HEADING
GOSPEL_HEADING
The following type of headings is recognized by being in uppercase and not consisting entirely of digits:
SUB_HEADING
The following type of headings is recognized by being correctly capitalized on a single line:
TITLE_HEADING
The following type of headings is recognized by its containing only the characters '*' and/or '-', or the string "page" after punctuation is removed, and appears only on a single line:
PAGE_BREAK_HEADING
- Parameters:
text
- The text to check for heading type.- Returns:
- The type of heading, or
NO_HEADING
if the heading could not be determined. - See Also:
containsTitleLabel(java.lang.String, java.lang.String)
,getSectionNumber(java.lang.String, java.lang.String)
-
isBreak
public static boolean isBreak(java.lang.String text)
Determines if the given text is a page break.A break is one of the following conditions:
- Text comprised solely of the following characters: '*', '-', '_', em-dash, and/or en-dash.
- The word "page" surrounded by only punctuation and/or whitespace.
- Parameters:
text
- The text to check.- Returns:
true
if the text is a page break heading.
-
isPageNumber
public static boolean isPageNumber(java.lang.String text)
Determines if the given text is a page number. A page number appears on a single line and has a page indicator and a number, along with an optional select set of symbols but no other letters.- Parameters:
text
- The text to check.- Returns:
true
if the text is a page number.
-
isSubHeading
public static boolean isSubHeading(java.lang.String text)
Determines if the given text is a subheading. A subheading is in all uppercase, is not composed completely of digits, and is not surrounded by quotation marks.- Parameters:
text
- The text to check.- Returns:
true
if the text is a subheading.
-
isTitleHeading
public static boolean isTitleHeading(java.lang.String text)
Determines if the given text is a title heading. A title heading appears on a single line and capitalizes each word, except for some exception words (such as "the" and "of").Popular prepositions used from Heather MacFadyen, University of Ottawa, at http://www.uottawa.ca/academic/arts/writcent/hypergrammar/preposit.html
- Parameters:
text
- The text to check.- Returns:
true
if the text is a title heading.
-
isTitleCapitalizationRequired
public static boolean isTitleCapitalizationRequired(java.lang.String word)
Determines if the given string should be capitalized if appearing in a title.- Parameters:
word
- The word to test for title capitalization.- Returns:
true
if the word should be capitalized in a title.
-
containsTitleLabel
public static boolean containsTitleLabel(java.lang.String text, java.lang.String label)
Determines if the given line contains a title label. The given label is matched case insensitively, but its first character must be capitalized.- Parameters:
text
- The text to check.label
- The label to match.- Returns:
true
if the given text contains the given title label.
-
containsOnlyIgnoreCase
public static boolean containsOnlyIgnoreCase(java.lang.String text, java.lang.String[] requiredLabels, java.lang.String[] optionalLabels)
Determines if the given line contains several required and optional labels, compared without case sensitivity.- Parameters:
text
- The text to check.requiredLabels
- The labels that must be present.optionalLabels
- The labels that are optional.- Returns:
true
if the given text contains the required labels and only the required and optional labels.
-
getSectionNumber
public static int getSectionNumber(java.lang.String text, java.lang.String sectionLabel)
Determines whether the given text is a numbered section heading, based upon the specified heading label. If so, the section number is returned.A numbered section appears in one of the following formats on a single line, with "chapter" used to represent the section label:
- Chapter 11
- Chapter 11: The Frightened Goat
- Chapter XI
- Chapter XI: The Frightened Goat
- Eleventh Chapter
- The Eleventh Chapter
- Parameters:
text
- The string to test for a section heading.sectionLabel
- The label used for this type of section, case-insensitive.- Returns:
- The value of this section, or -1 if the string does not appear to be of the given section type.
-
isQuoted
public static boolean isQuoted(java.lang.String string)
Determines if the given string is quoted.- Parameters:
string
- The string to check.- Returns:
true
if the string's first or last non-whitespace character is some sort of quotation mark.
-
-