本文整理汇总了Java中eu.riscoss.reasoner.Chunk类的典型用法代码示例。如果您正苦于以下问题:Java Chunk类的具体用法?Java Chunk怎么用?Java Chunk使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Chunk类属于eu.riscoss.reasoner包,在下文中一共展示了Chunk类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDoubleArrayFromDistribution
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
/**
* Converts the <code>Distribution</code> object to <code>double[]</code> array.
* @param distribution
* @param chunk (just for reference)
* @return <code>double[]</code> array
*/
private double[] getDoubleArrayFromDistribution(Distribution distribution, Chunk chunk) {
List<Double> values = distribution.getValues();
double[] result = new double[values.size()];
int i = 0; double sum = 0.0;
for (Double d : values) {
result[i++] = d.doubleValue();
sum += d;
}
/* sum != 1.0 */
// seems that we need to introduce less rigorous check here, because of the floating point imprecision
// therefore, lower and upper limits are introduced. 3 decimal places should be sufficient...
if(sum < DIST_SUM_LIMIT_LOW || sum > DIST_SUM_LIMIT_HI) {
throw new ReasonerException(String.format(
"Sum of distribution values [raw: " + sum + ", formatted: %f] is not equal to 1.0 for node: '%s'. "
+ "Check performed within limits: %f - %f", sum, chunk.getId(), DIST_SUM_LIMIT_LOW, DIST_SUM_LIMIT_HI));
}
return result;
}
示例2: getOutputModelSlice
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
/**
* Retrieves the chunk list for <code>ModelSlice.OUTPUT_DATA</code> or empty list if no chunks.
* In the context of KPA risk analysis tool, output is represented by RISK nodes, as well as INDICATOR nodes
* in the RISK network exclusively (tier 2, i.e. KPA level 3).
* @return chunk list
*/
private Iterable<Chunk> getOutputModelSlice() {
ArrayList<Chunk> chunks = new ArrayList<>();
for(String bnId : this.networkMap.keySet()) {
Network bn = this.networkMap.get(bnId);
String bnPropVal = getUserPropertyValue(bn.getUserProperties(), BN_TYPE_PROP_NAME);
if(BN_TYPE_PROP_VALUE_RISK.equals(bnPropVal)) {
// we only get the output from the RISK network - in the RISK network output
// is represented by all RISK nodes, as well as all INDICATOR nodes
chunks.addAll(getChunksForNodeType(bn, NODE_TYPE_PROP_VALUE_RISK));
chunks.addAll(getChunksForNodeType(bn, NODE_TYPE_PROP_VALUE_INDICATOR));
break;
}
}
return chunks;
}
示例3: getField
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
@Override
public Field getField(Chunk chunk, FieldType field) {
// should we check here if the node identified by input chunk actually exists / has value ?
// the thing is that SMILEException ( a runtime exception ), and this one will be thrown in
// the case node id (i.e. chunk id) supplied is invalid. It's wrapped in getFieldForChunk().
// E.G. smile.SMILEException: Invalid node id: VerticesXX
switch(field) {
case INPUT_VALUE:
return getDistributionFieldForChunk(chunk);
case OUTPUT_VALUE:
return getDistributionFieldForChunk(chunk);
case QUESTION:
// as explained, this should return a 'natural language' question.
// currently, this is extremely simplified, needs further discussion for forming proper questions
Field result = new Field(DataType.STRING,
String.format("What are the distribuion values for '%s' ?", chunk.getId()));
return result;
default:
return null;
// throw new ReasonerException("Unsupported field type");
}
}
示例4: invalidCountOfDistributionLevels
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
@Test
public void invalidCountOfDistributionLevels() {
engine = new KPARiskAnalysisTool();
engine.loadModel(convertStreamToString(
KPAUnitTesting.class.getResourceAsStream("resources/valid/Timeliness.xdsl")));
for (Chunk c : engine.queryModel(ModelSlice.INPUT_DATA)) {
if ("VAverage_bug_fix_time__days_".equals(c.getId())) {
Field f = engine.getField(c, FieldType.INPUT_VALUE);
System.out.println("Read default distribution: " + f.getValue());
List<Double> values = new ArrayList<Double>();
values.add(0.42);
values.add(0.22);
Distribution distribution = new Distribution();
distribution.setValues(values);
f.setValue(distribution);
this.exception.expect(ReasonerException.class);
engine.setField(c, FieldType.INPUT_VALUE, f);
break;
}
}
}
示例5: distributionSumNotEqualTo1
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
/**
* Test checks whether the exception is thrown for distribution sum > 1.0.
*/
@Test
public void distributionSumNotEqualTo1() {
engine.loadModel(convertStreamToString(KPAUnitTesting.class.getResourceAsStream("resources/valid/Timeliness.xdsl")));
Chunk chunk = new Chunk("VHour__When_the_commit_was_made", "Timeliness");
Distribution distribution = new Distribution();
List<Double> values = new ArrayList<>(0);
values.add(0.5);
values.add(0.4);
values.add(0.3);
distribution.setValues(values);
Field field = new Field(DataType.DISTRIBUTION, distribution);
this.exception.expect(ReasonerException.class);
this.engine.setField(chunk, FieldType.INPUT_VALUE, field);
}
示例6: runAnalysis
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
static Map<String, Map<String, Object>> runAnalysis(RiskAnalysisEngine riskAnalysisEngine)
{
Map<String, Map<String, Object>> result = new HashMap<String, Map<String, Object>>();
riskAnalysisEngine.runAnalysis(new String[0]);
Iterable<Chunk> chunks = riskAnalysisEngine.queryModel(ModelSlice.OUTPUT_DATA);
for (Chunk chunk : chunks) {
Field field = riskAnalysisEngine.getField(chunk, FieldType.OUTPUT_VALUE);
Map<String, Object> item = new HashMap<String, Object>();
Field descriptionField = riskAnalysisEngine.getField(chunk, FieldType.DESCRIPTION);
if (descriptionField != null) {
item.put("DESCRIPTION", riskAnalysisEngine.getField(chunk, FieldType.DESCRIPTION).getValue());
} else {
item.put("DESCRIPTION", chunk.getId());
}
item.put("TYPE", field.getDataType().toString());
item.put("VALUE", field.getValue());
result.put(chunk.getId(), item);
}
return result;
}
示例7: runAnalysis
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
static Map<String, Map<String, Object>> runAnalysis(RiskAnalysisEngine riskAnalysisEngine)
{
Map<String, Map<String, Object>> result = new HashMap<String, Map<String, Object>>();
riskAnalysisEngine.runAnalysis(new String[0]);
Iterable<Chunk> chunks = riskAnalysisEngine.queryModel(ModelSlice.OUTPUT_DATA);
for (Chunk chunk : chunks) {
Field field = riskAnalysisEngine.getField(chunk, FieldType.OUTPUT_VALUE);
Map<String, Object> item = new HashMap<String, Object>();
Field descriptionField = riskAnalysisEngine.getField(chunk, FieldType.DESCRIPTION);
if (descriptionField != null) {
item.put("description", descriptionField.getValue());
}
Field labelField = riskAnalysisEngine.getField(chunk, FieldType.LABEL);
if (labelField != null) {
item.put("label", labelField.getValue());
}
item.put("type", field.getDataType().toString());
item.put("value", field.getValue());
result.put(chunk.getId(), item);
}
return result;
}
示例8: getChunksForNodeType
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
/**
* Get chunk list for specific node type in the given BN.
* @param bn BayesiaN network
* @param nodeType node type
* @return
*/
private Collection<Chunk> getChunksForNodeType(Network bn, String nodeType) {
ArrayList<Chunk> chunks = new ArrayList<>();
for(int hNode : bn.getAllNodes()) {
String propVal = getUserPropertyValue(
bn.getNodeUserProperties(hNode), NODE_TYPE_PROP_NAME);
if(propVal != null && nodeType.toUpperCase().equals(propVal)) {
Chunk chunk = new Chunk(bn.getNodeId(hNode), bn.getId());
chunks.add(chunk);
}
}
return chunks;
}
示例9: getInputModelSlice
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
/**
* Retrieves the chunk list for <code>ModelSlice.INPUT_DATA</code> or empty list if no chunks.
* @return chunk list
*/
private Iterable<Chunk> getInputModelSlice() {
ArrayList<Chunk> chunks = new ArrayList<>();
for(String bnId : this.networkMap.keySet()) {
Network bn = this.networkMap.get(bnId);
// we get input chunks from indicator networks (tier 1), therefore those nodes
// are marked as such (in KPA terminology: risk drivers)
// we also need to get input chunks from Risk network (tier 2), therefore those
// nodes are also marked as such (in KPA terminology: contextual indicators)
chunks.addAll(getChunksForNodeType(bn, NODE_TYPE_PROP_VALUE_INPUT));
}
return chunks;
}
示例10: queryModel
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
@Override
public Iterable<Chunk> queryModel(ModelSlice slice) {
// if(this.networkMap.keySet() == null || this.networkMap.keySet().isEmpty())
// throw new ReasonerException("No model was loaded");
switch(slice) {
case INPUT_DATA:
return getInputModelSlice();
case OUTPUT_DATA:
return getOutputModelSlice();
default:
throw new ReasonerException("Unsupported model-slice type");
}
}
示例11: queryInputBeforeLoad
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
/**
* Query before-load, or invalid type
*/
@Test
public void queryInputBeforeLoad() {
// this.exception.expect(ReasonerException.class);
// should return empty collection (arrayList)
engine = new KPARiskAnalysisTool();
Iterable<Chunk> res = engine.queryModel(ModelSlice.INPUT_DATA);
Assert.assertTrue(res instanceof ArrayList<?> && ((ArrayList<Chunk>)res).isEmpty());
}
示例12: queryOutputBeforeLoad
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
@Test
public void queryOutputBeforeLoad() {
// this.exception.expect(ReasonerException.class);
// should return empty collection (arrayList)
engine = new KPARiskAnalysisTool();
Iterable<Chunk> res = engine.queryModel(ModelSlice.OUTPUT_DATA);
Assert.assertTrue(res instanceof ArrayList<?> && ((ArrayList<Chunk>)res).isEmpty());
}
示例13: getQuestion
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
/**
* Confirm a question is returned (not quite rigorous...)
*/
@Test
public void getQuestion() {
engine = new KPARiskAnalysisTool();
engine.loadModel(convertStreamToString(
KPAUnitTesting.class.getResourceAsStream("resources/valid/Timeliness.xdsl")));
Field f = engine.getField(new Chunk("VCommit_frequency___week", "Timeliness"), FieldType.QUESTION);
Assert.assertTrue(f.getDataType() == DataType.STRING);
Assert.assertTrue(f.getValue() != "");
}
示例14: getFieldOfInvalidType
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
/**
* Getting / setting fields of invalid type
*/
@Test
public void getFieldOfInvalidType() {
this.exception.expect(ReasonerException.class);
engine.getField(new Chunk(), FieldType.DESCRIPTION);
this.exception.expect(ReasonerException.class);
engine.getField(new Chunk(), FieldType.WEIGHT);
}
示例15: setFieldOfInvalidType
import eu.riscoss.reasoner.Chunk; //导入依赖的package包/类
@Test
public void setFieldOfInvalidType() {
this.exception.expect(ReasonerException.class);
Field field = new Field(DataType.EVIDENCE, null);
engine.setField(new Chunk(), FieldType.INPUT_VALUE, field);
}