手机配件网站模板,腾讯云做网站选哪个,淘宝客模板wordpress,建立网站要怎么做latex段落悬挂缩进这篇文章显示了如何使用正则表达式将缩进的长段落挂起。 该方法将考虑单词边界#xff0c;这意味着它不会破坏缩进单词。 为了说明此问题#xff0c;请考虑以下示例#xff1a; 近年来#xff0c;人们越来越努力从自然语言文本中提取实体之间的关系。 在… latex段落悬挂缩进 这篇文章显示了如何使用正则表达式将缩进的长段落挂起。 该方法将考虑单词边界这意味着它不会破坏缩进单词。 为了说明此问题请考虑以下示例 近年来人们越来越努力从自然语言文本中提取实体之间的关系。 在这篇论文中我将集中于认识科学文章中报道的实体之间的生物医学关系的各个方面。 输出应为 There has been an increasing effort in recent years to extract relations betweenentities from natural language text. In this dissertation, I will focus onvarious aspects of recognizing biomedical relations between entities reportedin scientific articles.我的方法 我们需要一个正则表达式将段落分成固定长度的字符串序列。 假设文本宽度为80而缩进量为3则第一个字符串的长度为80。其余所有字符的长度为77。 该算法的主要过程如下 获取前80个字符 对于其余的字符串将拆分点替换为三个空格 为了找到分裂点我们使用正则表达式(.{1,77})\s 。 此正则表达式搜索一个长度小于等于77并且最后一个字符不是空格的子字符串。 找到它之后我们将组 $1 替换$1\n 。 因此java代码应如下所示 String regex (.{1,77})\\s;
String replacement $1\n;
text.replaceAll(regex, replacement); 除了最后一行此正则表达式工作完美。 如果给定的文本不以空格结尾例如\n 则最后一行将无法正确处理。 将最后一行视为 in scientific articles. 在最后一次搜索中正则表达式无法在行尾找到空白因此它将在“科学”和“文章”之间定位空格。 结果我们将得到 ...in scientific
articles. 为了克服这个问题我在段落末尾添加了一个假的“ \ n”。 格式化后我将其删除。 代码的其他部分都很简单。 在这里我附上我的源代码。 我使用Apache公共库来生成缩进空间并声明缩进的有效性。 有关最新代码您可以查看我的Github /*** Format a paragraph to that has all lines but the first indented.* * param text text to be formatted* param hangIndent hanging indentation. hangIndent 0* param width the width of formatted paragraph* param considerSpace true if only split at white spaces.* return*/public static String hangIndent(String text, int hangIndent, int width,boolean considerSpace) {Validate.isTrue(hangIndent 0,hangIndent should not be negative: %d,hangIndent);Validate.isTrue(width 0, text width should not be negative: %d,width);Validate.isTrue(hangIndent width,hangIndent should not be less than width: hangIndent%d, width%d,hangIndent,width);StringBuilder sb new StringBuilder(text.substring(0, hangIndent));// Needed to handle last line correctly.// Will be trimmed at lasttext text.substring(hangIndent) \n;// hang indentString spaces org.apache.commons.lang3.StringUtils.repeat( , hangIndent);String replacement spaces $1\n;String regex (.{1, (width - hangIndent) });if (considerSpace) {regex \\s;}text text.replaceAll(regex, replacement);// remove first spaces and last \ntext text.substring(hangIndent, text.length() - 1);return sb.append(text).toString();}相关工作 还有许多其他方法可以实现悬挂缩进功能。 最简单的方法似乎是先将段落分成单词然后使用计数器来计算当前行的长度。 只要超过最大长度我们就会添加换行符和缩进。 我不确定哪种方法更有效但是绝对非常规表达方法更容易实现和维护。 所以我想这篇文章的重点是学习一些“ NEW ”。 参考 使用regex可以从PGuru博客上的JCG合作伙伴 Peng Yifan挂起的 Java中的段落缩进 。 翻译自: https://www.javacodegeeks.com/2014/01/using-regex-to-hanging-indent-a-paragraph-in-java.htmllatex段落悬挂缩进