@Test public void fromOkapiSegment() { TextFragment tf = new TextFragment("Hello "); tf.append(new Code(TagType.OPENING, "bold", "<b>")); tf.append("world"); tf.append(new Code(TagType.CLOSING, "bold", "</b>")); Segment segment = new Segment("seg1", tf); WSTextSegmentData data = WSTextSegmentData.fromOkapiSegment(segment); assertEquals("Hello " + WSFilter.PLACEHOLDER + "world" + WSFilter.PLACEHOLDER, data.getText()); assertArrayEquals(new String[] { "<b>", "</b>" }, data.getPlaceholders()); }
public static WSTextSegmentData fromOkapiSegment(Segment okapiSeg) { List<String> wsPlaceholders = new ArrayList<String>(); StringBuilder wsContent = new StringBuilder(); TextFragment okapiContent = okapiSeg.getContent(); List<Code> okapiCodes = okapiContent.getCodes(); String okapiCodedText = okapiContent.getCodedText(); int codedTextLen = okapiCodedText.length(); for (int i = 0; i < codedTextLen; i++) { char c = okapiCodedText.charAt(i); if (TextFragment.isMarker(c)) { int codeIndex = TextFragment.toIndex(okapiCodedText.charAt(++i)); wsContent.append(WSFilter.PLACEHOLDER); Code code = okapiCodes.get(codeIndex); wsPlaceholders.add(code.hasOuterData() ? code.getOuterData() : code.getData()); } else { wsContent.append(c); } } return new WSTextSegmentData(wsContent.toString(), wsPlaceholders.toArray(new String[wsPlaceholders.size()])); }
WSTextSegmentData { public static WSTextSegmentData fromOkapiSegment(Segment okapiSeg) { List<String> wsPlaceholders = new ArrayList<String>(); StringBuilder wsContent = new StringBuilder(); TextFragment okapiContent = okapiSeg.getContent(); List<Code> okapiCodes = okapiContent.getCodes(); String okapiCodedText = okapiContent.getCodedText(); int codedTextLen = okapiCodedText.length(); for (int i = 0; i < codedTextLen; i++) { char c = okapiCodedText.charAt(i); if (TextFragment.isMarker(c)) { int codeIndex = TextFragment.toIndex(okapiCodedText.charAt(++i)); wsContent.append(WSFilter.PLACEHOLDER); Code code = okapiCodes.get(codeIndex); wsPlaceholders.add(code.hasOuterData() ? code.getOuterData() : code.getData()); } else { wsContent.append(c); } } return new WSTextSegmentData(wsContent.toString(), wsPlaceholders.toArray(new String[wsPlaceholders.size()])); } }
WSTextSegmentData { public static WSTextSegmentData fromOkapiSegment(Segment okapiSeg) { List<String> wsPlaceholders = new ArrayList<String>(); StringBuilder wsContent = new StringBuilder(); TextFragment okapiContent = okapiSeg.getContent(); List<Code> okapiCodes = okapiContent.getCodes(); String okapiCodedText = okapiContent.getCodedText(); int codedTextLen = okapiCodedText.length(); for (int i = 0; i < codedTextLen; i++) { char c = okapiCodedText.charAt(i); if (TextFragment.isMarker(c)) { int codeIndex = TextFragment.toIndex(okapiCodedText.charAt(++i)); wsContent.append(WSFilter.PLACEHOLDER); Code code = okapiCodes.get(codeIndex); wsPlaceholders.add(code.hasOuterData() ? code.getOuterData() : code.getData()); } else { wsContent.append(c); } } return new WSTextSegmentData(wsContent.toString(), wsPlaceholders.toArray(new String[wsPlaceholders.size()])); } private  WSTextSegmentData(String text, String[] placeholders); }
WSTextSegmentData { public static WSTextSegmentData fromOkapiSegment(Segment okapiSeg) { List<String> wsPlaceholders = new ArrayList<String>(); StringBuilder wsContent = new StringBuilder(); TextFragment okapiContent = okapiSeg.getContent(); List<Code> okapiCodes = okapiContent.getCodes(); String okapiCodedText = okapiContent.getCodedText(); int codedTextLen = okapiCodedText.length(); for (int i = 0; i < codedTextLen; i++) { char c = okapiCodedText.charAt(i); if (TextFragment.isMarker(c)) { int codeIndex = TextFragment.toIndex(okapiCodedText.charAt(++i)); wsContent.append(WSFilter.PLACEHOLDER); Code code = okapiCodes.get(codeIndex); wsPlaceholders.add(code.hasOuterData() ? code.getOuterData() : code.getData()); } else { wsContent.append(c); } } return new WSTextSegmentData(wsContent.toString(), wsPlaceholders.toArray(new String[wsPlaceholders.size()])); } private  WSTextSegmentData(String text, String[] placeholders); String getText(); String[] getPlaceholders(); static WSTextSegmentData fromOkapiSegment(Segment okapiSeg); }
WSTextSegmentData { public static WSTextSegmentData fromOkapiSegment(Segment okapiSeg) { List<String> wsPlaceholders = new ArrayList<String>(); StringBuilder wsContent = new StringBuilder(); TextFragment okapiContent = okapiSeg.getContent(); List<Code> okapiCodes = okapiContent.getCodes(); String okapiCodedText = okapiContent.getCodedText(); int codedTextLen = okapiCodedText.length(); for (int i = 0; i < codedTextLen; i++) { char c = okapiCodedText.charAt(i); if (TextFragment.isMarker(c)) { int codeIndex = TextFragment.toIndex(okapiCodedText.charAt(++i)); wsContent.append(WSFilter.PLACEHOLDER); Code code = okapiCodes.get(codeIndex); wsPlaceholders.add(code.hasOuterData() ? code.getOuterData() : code.getData()); } else { wsContent.append(c); } } return new WSTextSegmentData(wsContent.toString(), wsPlaceholders.toArray(new String[wsPlaceholders.size()])); } private  WSTextSegmentData(String text, String[] placeholders); String getText(); String[] getPlaceholders(); static WSTextSegmentData fromOkapiSegment(Segment okapiSeg);  }