<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">The routine is not very bright. The issue that the inserted space is trying to handle is when text in one block element is followed by text perhaps in another block element.<div><br></div><div>A block element implies a newline. The seg element is an inline element and does not imply added spacing. However, it is only an issue if elements split words.</div><div><br></div><div>So the fix is to categorize each element as block or inline and smartly putting the extra space where it is needed.</div><div><br></div><div>Need to verify how ruby is handled in OSIS. Or change this may break that.</div><div><br></div><div>Please file a bug.</div><div><br></div><div>In Him,</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>DM</div><div><br><div><div>On Sep 26, 2012, at 3:47 PM, Chris Burrell &lt;<a href="mailto:chris@burrell.me.uk">chris@burrell.me.uk</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi</div><div><br></div><div>I have a question around the <i>seg </i>element in OSIS. Versions like the WLC have separated each part of the word as a seg (see below). And then separates the words (sets of segs) with spaces.</div>
<div><br></div><div>&lt;div&gt;&lt;title type="x-gen"&gt;Genesis 1:1&lt;/title&gt;&lt;verse osisID="Gen.1.1"&gt;&lt;seg type="x-morph"&gt;בְּ&lt;/seg&gt;&lt;seg type="x-morph"&gt;רֵאשִׁ֖ית&lt;/seg&gt; &lt;seg type="x-morph"&gt;בָּרָ֣א&lt;/seg&gt; &lt;seg type="x-morph"&gt;אֱלֹהִ֑ים&lt;/seg&gt; &lt;seg type="x-morph"&gt;אֵ֥ת&lt;/seg&gt; &lt;seg type="x-morph"&gt;הַ&lt;/seg&gt;&lt;seg type="x-morph"&gt;שָּׁמַ֖יִם&lt;/seg&gt; &lt;seg type="x-morph"&gt;וְ&lt;/seg&gt;&lt;seg type="x-morph"&gt;אֵ֥ת&lt;/seg&gt; &lt;seg type="x-morph"&gt;הָ&lt;/seg&gt;&lt;seg type="x-morph"&gt;אָֽרֶץ׃&lt;/seg&gt; &lt;/verse&gt;&lt;/div&gt;</div>
<div><br></div><div>The JSword compare functionality (and indexing) uses&nbsp;OSISUtil.getCanonicalText(). This seems to add spaces between the seg elements which then makes for inconsistent results in the diffing (extra differences). The following comment is seen in the method:</div>
<div><div>&nbsp;// make sure that adjacent text elements are separated by&nbsp;whitespace</div><div>// TODO(dms): verify that the xml parser does not split words&nbsp;containing entities.</div></div><div><br></div><div>Presumably, we want to add an exception for <i>seg</i>&nbsp;elements. I assume indexing/searching is also going to be affected by this problem...</div>
<div><br></div><div>My question is whether to add a new block in the instanceof Element part. Or in the instanceof Text part?&nbsp;</div><div>Also, are there any other times ever where we want additional spaces between segs? Any other gotchas?</div>
<div><br></div><div>(see below for JSword function)</div><div>Cheers</div><div>Chris</div><div><br></div><div>Copy of the function in JSword:</div><div><br></div><div><div><b>public static String getCanonicalText(Element root) {</b></div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; StringBuilder buffer = new StringBuilder();</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; // Dig past osis, osisText, if present, to get to the real content.</div><div>&nbsp; &nbsp; &nbsp; &nbsp; List&lt;Content&gt; frag = OSISUtil.getFragment(root);</div>
<div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; Iterator&lt;Content&gt; dit = frag.iterator();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; String sID = null;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Content data = null;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Element ele = null;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; while (dit.hasNext()) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data = dit.next();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (data instanceof Element) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ele = (Element) data;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!isCanonical(ele)) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (ele.getName().equals(OSISUtil.OSIS_ELEMENT_VERSE)) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sID = ele.getAttributeValue(OSISUtil.OSIS_ATTR_SID);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (sID != null) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getCanonicalContent(ele, sID, dit, buffer);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getCanonicalContent(ele, null, ele.getContent().iterator(), buffer);</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if (data instanceof Text) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // make sure that adjacent text elements are separated by</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // whitespace</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // TODO(dms): verify that the xml parser does not split words</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // containing entities.</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int lastIndex = buffer.length() - 1;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String text = ((Text) data).getText();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Ignore empty text nodes.</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (text.length() != 0) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (lastIndex &gt;= 0 &amp;&amp; !Character.isWhitespace(buffer.charAt(lastIndex)) &amp;&amp; !Character.isWhitespace(text.charAt(0))) {</div><div>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer.append(' ');</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer.append(text);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br>
</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return buffer.toString().trim();</div><div>&nbsp; &nbsp; }</div></div><div><br></div><div><br></div><div>Cheers</div><div>Chris</div><div><br></div>
_______________________________________________<br>jsword-devel mailing list<br><a href="mailto:jsword-devel@crosswire.org">jsword-devel@crosswire.org</a><br>http://www.crosswire.org/mailman/listinfo/jsword-devel<br></blockquote></div><br></div></body></html>