public boolean isCorrect(String word, String... uris) { try { RequestParameters params = new RequestParameters(); params.add("service", "is-correct"); params.add("word", word); params.add("uris", uris); XMLStreamReaderHandle readHandle = new XMLStreamReaderHandle(); // call the service getServices().get(params, readHandle); QName correctName = new QName(XMLConstants.DEFAULT_NS_PREFIX, "correct"); XMLStreamReader streamReader = readHandle.get(); while (streamReader.hasNext()) { int current = streamReader.next(); if (current == XMLStreamReader.START_ELEMENT) { if (correctName.equals(streamReader.getName())) { return "true".equals(streamReader.getElementText()); } } } return false; } catch (XMLStreamException ex) { throw new RuntimeException(ex); } }
public String[] suggest( String word, Integer maximum, Integer distanceThreshold, String... uris) { try { RequestParameters params = new RequestParameters(); params.add("service", "suggest-detailed"); params.add("word", word); params.add("uris", uris); if (maximum != null) params.add("maximum", String.valueOf(maximum)); if (distanceThreshold != null) params.add("distance-threshold", String.valueOf(distanceThreshold)); XMLStreamReaderHandle readHandle = new XMLStreamReaderHandle(); // call the service getServices().get(params, readHandle); XMLStreamReader streamReader = readHandle.get(); QName wordName = new QName("http://marklogic.com/xdmp/spell", "word"); ArrayList<String> words = new ArrayList<String>(); while (streamReader.hasNext()) { int current = streamReader.next(); if (current == XMLStreamReader.START_ELEMENT) { if (wordName.equals(streamReader.getName())) { words.add(streamReader.getElementText()); } } } return words.toArray(new String[words.size()]); } catch (XMLStreamException ex) { throw new RuntimeException(ex); } }