@@ -38,6 +38,9 @@ public class RelationshipExtraction extends WatsonService {
3838
3939 /** The dataset. */
4040 private Dataset dataset ;
41+
42+ /** The return type. */
43+ private String returnType = "xml" ;
4144
4245 /**
4346 * Instantiates a new relationship extraction service.
@@ -65,15 +68,15 @@ public RelationshipExtraction() {
6568 *
6669 * @param text the text to analyze
6770 *
68- * @return the result as XML string
71+ * @return the result as an XML/JSON string
6972 */
7073 public String extract (final String text ) {
7174 Validate .notNull (dataset , "dataset cannot be null" );
7275 Validate .notNull (text , "text cannot be null" );
7376
7477 final Request request =
7578 RequestBuilder .post ("/v1/sire/0" )
76- .withForm ("sid" , dataset .getId (), "rt" , "xml" , "txt" , text ).build ();
79+ .withForm ("sid" , dataset .getId (), "rt" , returnType , "txt" , text ).build ();
7780 final Response response = execute (request );
7881 return ResponseUtil .getString (response );
7982 }
@@ -96,5 +99,18 @@ public Dataset getDataset() {
9699 public void setDataset (final Dataset dataset ) {
97100 this .dataset = dataset ;
98101 }
102+
103+ /**
104+ * Sets the returnType.
105+ *
106+ * @param returnType the new returnType
107+ */
108+ public void setReturnType (final ReturnType returnType ) {
109+ if (returnType == ReturnType .XML ) {
110+ this .returnType = "xml" ;
111+ } else if (returnType == ReturnType .JSON ) {
112+ this .returnType = "json" ;
113+ }
114+ }
99115
100116}
0 commit comments