Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less generic parsers #81

Open
cbonesana opened this issue Jun 21, 2021 · 2 comments
Open

Less generic parsers #81

cbonesana opened this issue Jun 21, 2021 · 2 comments

Comments

@cbonesana
Copy link
Member

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...

@rcabanasdepaz
Copy link
Collaborator

rcabanasdepaz commented Jun 22, 2021

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.

@cbonesana
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants