org.dmg.pmml.Extension Java Examples

The following examples show how to use org.dmg.pmml.Extension. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PMMLPipeline.java    From jpmml-sklearn with GNU Affero General Public License v3.0 5 votes vote down vote up
private PMML encodePMML(Model model, String repr, SkLearnEncoder encoder){
	PMML pmml = encoder.encodePMML(model);

	if(repr != null){
		Extension extension = new Extension()
			.addContent(repr);

		MiningBuildTask miningBuildTask = new MiningBuildTask()
			.addExtensions(extension);

		pmml.setMiningBuildTask(miningBuildTask);
	}

	return pmml;
}
 
Example #2
Source File: FormulaUtil.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
static
private Extension createExtension(String content){
	Extension extension = new Extension()
		.addContent(content);

	return extension;
}
 
Example #3
Source File: AppPMMLUtils.java    From oryx with Apache License 2.0 5 votes vote down vote up
/**
 * @param pmml PMML model to add extension to, with a single {@code String} content and no value.
 *  The content is encoded as if they were being added to a PMML {@link Array} and are
 *  space-separated with PMML quoting rules
 * @param key extension key
 * @param content list of values to add as a {@code String}
 */
public static void addExtensionContent(PMML pmml, String key, Collection<?> content) {
  if (content.isEmpty()) {
    return;
  }
  String joined = TextUtils.joinPMMLDelimited(content);
  pmml.addExtensions(new Extension().setName(key).addContent(joined));
}
 
Example #4
Source File: NaiveBayesModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
private List<BayesInput> parseBayesInputs(NaiveBayesModel naiveBayesModel){
	BayesInputs bayesInputs = naiveBayesModel.getBayesInputs();

	if(!bayesInputs.hasExtensions()){
		return bayesInputs.getBayesInputs();
	}

	List<BayesInput> result = new ArrayList<>(bayesInputs.getBayesInputs());

	// The support for continuous fields using the TargetValueStats element was officially introduced in PMML schema version 4.2.
	// However, it is possible to encounter this feature in older PMML schema version documents (most notably, produced by R's "pmml" package),
	// where the offending BayesInput element is surrounded by an Extension element:
	// <BayesInputs>
	//   <BayesInput>
	//     <PairCounts/>
	//   </BayesInput>
	//   <Extension>
	//     <BayesInput>
	//       <TargetValueStats/>
	//     </BayesInput>
	//   </Extension>
	// </BayesInputs>
	List<Extension> extensions = bayesInputs.getExtensions();
	for(Extension extension : extensions){
		List<?> objects = extension.getContent();

		for(Object object : objects){

			if(object instanceof BayesInput){
				BayesInput bayesInput = (BayesInput)object;

				result.add(bayesInput);
			}
		}
	}

	return result;
}
 
Example #5
Source File: AppPMMLUtils.java    From oryx with Apache License 2.0 4 votes vote down vote up
public static String getExtensionValue(PMML pmml, String name) {
  return pmml.getExtensions().stream().filter(extension -> name.equals(extension.getName())).findFirst().
      map(Extension::getValue).orElse(null);
}
 
Example #6
Source File: Node.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public List<Extension> getExtensions(){
	throw new UnsupportedOperationException();
}
 
Example #7
Source File: Node.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Node addExtensions(Extension... extensions){
	getExtensions().addAll(Arrays.asList(extensions));

	return this;
}
 
Example #8
Source File: MixedContentTest.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
static
private List<?> getDeepContent(Object object){
	Extension extension = (Extension)object;

	return extension.getContent();
}
 
Example #9
Source File: ValidationTest.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
static
private void checkExtension(String name, String value, Extension extension){
	assertEquals(name, extension.getName());
	assertEquals(value, extension.getValue());
}
 
Example #10
Source File: InlineTableUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
static
Table<Integer, String, Object> parse(InlineTable inlineTable){
	Table<Integer, String, Object> result = HashBasedTable.create();

	Integer rowKey = 1;

	List<Row> rows = inlineTable.getRows();
	for(Row row : rows){
		List<Object> cells = row.getContent();

		for(Object cell : cells){
			String column;
			Object value;

			if(cell instanceof Cell){
				Cell pmmlCell = (Cell)cell;

				column = parseColumn(pmmlCell.getName());
				value = pmmlCell.getValue();
			} else

			if(cell instanceof Extension){
				continue;
			} else

			if(cell instanceof PMMLObject){
				PMMLObject object = (PMMLObject)cell;

				throw new MisplacedElementException(object);
			} else

			if(cell instanceof JAXBElement){
				JAXBElement<?> jaxbElement = (JAXBElement<?>)cell;

				column = parseColumn(jaxbElement.getName());
				value = jaxbElement.getValue();
			} else

			if(cell instanceof Element){
				Element domElement = (Element)cell;

				column = domElement.getTagName();
				value = domElement.getTextContent();
			} else

			if(cell instanceof String){
				String string = (String)cell;

				if(("").equals(string.trim())){
					continue;
				}

				throw new InvalidElementException(row);
			} else

			{
				throw new InvalidElementException(row);
			}

			result.put(rowKey, column, value);
		}

		rowKey += 1;
	}

	return result;
}
 
Example #11
Source File: ExtensionUtil.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
static
public List<?> getContent(HasExtensions<?> hasExtensions){
	List<Extension> extensions = hasExtensions.getExtensions();

	assertEquals(1, extensions.size());

	Extension extension = extensions.get(0);

	return extension.getContent();
}
 
Example #12
Source File: AppPMMLUtils.java    From oryx with Apache License 2.0 2 votes vote down vote up
/**
 * @param pmml PMML model to add extension to, with no content. It may possibly duplicate
 *  existing extensions.
 * @param key extension key
 * @param value extension value
 */
public static void addExtension(PMML pmml, String key, Object value) {
  pmml.addExtensions(new Extension().setName(key).setValue(value.toString()));
}
 
Example #13
Source File: NodeTest.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
@Test
public void jaxbClone() throws Exception {
	Node node1 = new BranchNode(null, True.INSTANCE)
		.setId(new Integer(1));

	List<Node> nodes = node1.getNodes();

	Node node2a = new ComplexNode(False.INSTANCE)
		.setId("2a")
		.addExtensions(new Extension());

	nodes.add(node2a);

	Node node2b = new LeafNode(null, True.INSTANCE)
		.setId("2b");

	nodes.add(node2b);

	node1
		.setDefaultChild(node2b);

	TreeModel treeModel = new TreeModel()
		.setNode(node1);

	TreeModel jaxbTreeModel = (TreeModel)clone(treeModel);

	Node jaxbNode1 = jaxbTreeModel.getNode();

	assertEquals(node1.getClass(), jaxbNode1.getClass());
	assertEquals(1, node1.getId());
	assertEquals("1", jaxbNode1.getId());
	assertEquals(node2b, node1.getDefaultChild());
	assertEquals("2b", jaxbNode1.getDefaultChild());

	List<Node> jaxbNodes = jaxbNode1.getNodes();

	assertEquals(2, jaxbNodes.size());

	Node jaxbNode2a = jaxbNodes.get(0);

	assertEquals(node2a.getClass(), jaxbNode2a.getClass());
	assertEquals(node2a.getId(), jaxbNode2a.getId());

	assertTrue(jaxbNode2a.hasExtensions());

	Node jaxbNode2b = jaxbNodes.get(1);

	assertEquals(node2b.getClass(), jaxbNode2b.getClass());
	assertEquals(node2b.getId(), jaxbNode2b.getId());
}