Open cbonesana opened 3 years ago
As far as I understand, the problem is that the user needs to do the casting but he might not be sure of the type:
DAGModel<BayesianFactor> bent = (DAGModel<BayesianFactor>) UAIParser.read("file.uai")
One alternative might be to add an addition method that returns the actual parser (eventually with other names):
DAGModel<BayesianFactor> bent = UAIParser.get("file.uai").parse()
The good of this is that we could keep the old interface too.
No, that's not the problem.
First, there is no need for casting anything since the UAIParser.read(String)
method is already generic. The return type is controlled by the assigned variable type. And this is the issue.
See the following examples.
DAGModel<BayesianFactor> bayes = UAIParser.read("bayesian.uai");
DAGModel<VertexFactor> stillBayes = UAIParser.read("bayesian.uai");
Both of these statements are valid but the second one will generate an error since it will read a BayesianFactor
(as indicated in the bayesian.uai
file) but then it will be assigned to a VertexFactor
.
In many format file it is written which kind of Factor is stored. Yet we use this information to read the file with the correct parsers but we delegate to the developer to guess the type.
It would be useful to have a way to find the type of factors without using
instanceof
or assuming that the final users are nice people that never make mistakes...