lucmoreau / ProvToolbox

Java toolkit to create and convert W3C PROV data model representations, and build provenance-enabled applications in a variety of programming languages (java, python, typescript, javascript)
Other
75 stars 42 forks source link

Generated BindingsBeans does not compile due to duplicate methods #160

Closed saskiawagenaar closed 1 year ago

saskiawagenaar commented 5 years ago

Using the following simple PROV template:

document
        prefix var <http://openprovenance.org/var#>
        prefix vargen <http://openprovenance.org/vargen#>
        prefix ex <http://example.com#>
        bundle ex:b
                agent(var:agent,[prov:type = 'prov:Person'])
                entity(var:entity1, [prov:type="entity1"])
                entity(var:entity2, [prov:type="entity2", ex:entity1='var:entity1'])
                activity(var:activity,[prov:location = 'var:tree'])
                wasAssociatedWith(vargen:assocId; var:activity, var:agent,-)
                wasGeneratedBy(var:entity1,var:activity,-)
        endBundle
endDocument

and then generating BindingsBeans for them using the provtoolbox, the resulting BindingsBean will not compile due to the duplicate method public void addEntity1(QualifiedName arg):

// Generated Automatically by ProvToolbox for template "TestTemplate"
package nl.knmi;

import java.lang.String;
import org.openprovenance.prov.model.ProvFactory;
import org.openprovenance.prov.model.QualifiedName;
import org.openprovenance.prov.template.expander.Bindings;
import org.openprovenance.prov.template.expander.BindingsBean;

public class TestTemplateBindingsBean implements BindingsBean {
  private final Bindings bindings;

  private final ProvFactory pf;

  public TestTemplateBindingsBean(ProvFactory pf) {
    this.pf = pf;
    this.bindings = new Bindings(pf);
  }

  public void addActivity(QualifiedName arg) {
    bindings.addVariable("activity",arg);
  }

  public void addAgent(QualifiedName arg) {
    bindings.addVariable("agent",arg);
  }

  public void addEntity2(QualifiedName arg) {
    bindings.addVariable("entity2",arg);
  }

  public void addEntity1(QualifiedName arg) {
    bindings.addVariable("entity1",arg);
  }

  public void addAssocid(QualifiedName arg) {
    bindings.addVariable("assocId",arg);
  }

  public void addEntity1(QualifiedName arg) {
    bindings.addAttribute("entity1",arg);
  }

  public void addEntity1(String arg) {
    bindings.addAttribute("entity1",arg);
  }

  public void addTree(QualifiedName arg) {
    bindings.addAttribute("tree",arg);
  }

  public void addTree(String arg) {
    bindings.addAttribute("tree",arg);
  }

  public Bindings getBindings() {
    return bindings;
  }

  public String getTemplate() {
    return "src/main/resources/TestTemplate.provn";
  }
}

The issue seems to arise because var:entity1 is used both as the entity id as well as an attribute. Since generated methods for adding attributes and variables both have the same naming convention, the resulting BindingsBean will have a duplicate method signature and will not compile.

lucmoreau commented 5 years ago

Dear Saskia, Thanks for flagging this issue. Are you able to provide me with the command you executed so that I can reproduce the problem? Best regards

-- Professor Luc Moreau, Head of Department Department of Informatics, King’s College London Strand Campus, Bush House, 30 Aldwych, London, WC2B 4BG. Tel: +44 207 848 6808, web: https://nms.kcl.ac.uk/luc.moreau/https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fnms.kcl.ac.uk%2Fluc.moreau%2F&data=01%7C01%7Cluc.moreau%40kcl.ac.uk%7Cb86b7dc3862647040ff308d70611a6ae%7C8370cf1416f34c16b83c724071654356%7C0&sdata=Xc8kT1rwPqQ3aeCARMIkFoULEy65Bah%2FR3sjk10GUsw%3D&reserved=0

From: Saskia Wagenaar notifications@github.com Reply to: lucmoreau/ProvToolbox reply@reply.github.com Date: Thursday, 12 September 2019 at 17:16 To: lucmoreau/ProvToolbox ProvToolbox@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [lucmoreau/ProvToolbox] Generated BindingsBeans does not compile due to duplicate methods (#160)

Using the following simple PROV template:

document

    prefix var <http://openprovenance.org/var#>

    prefix vargen <http://openprovenance.org/vargen#>

    prefix ex <http://example.com#>

    bundle ex:b

            agent(var:agent,[prov:type = 'prov:Person'])

            entity(var:entity1, [prov:type="entity1"])

            entity(var:entity2, [prov:type="entity2", ex:entity1='var:entity1'])

            activity(var:activity,[prov:location = 'var:tree'])

            wasAssociatedWith(vargen:assocId; var:activity, var:agent,-)

            wasGeneratedBy(var:entity1,var:activity,-)

    endBundle

endDocument

and then generating BindingsBeans for them using the provtoolbox, the resulting BindingsBean will not compile due to the duplicate method public void addEntity1(QualifiedName arg):

// Generated Automatically by ProvToolbox for template "TestTemplate"

package nl.knmi;

import java.lang.String;

import org.openprovenance.prov.model.ProvFactory;

import org.openprovenance.prov.model.QualifiedName;

import org.openprovenance.prov.template.expander.Bindings;

import org.openprovenance.prov.template.expander.BindingsBean;

public class TestTemplateBindingsBean implements BindingsBean {

private final Bindings bindings;

private final ProvFactory pf;

public TestTemplateBindingsBean(ProvFactory pf) {

this.pf = pf;

this.bindings = new Bindings(pf);

}

public void addActivity(QualifiedName arg) {

bindings.addVariable("activity",arg);

}

public void addAgent(QualifiedName arg) {

bindings.addVariable("agent",arg);

}

public void addEntity2(QualifiedName arg) {

bindings.addVariable("entity2",arg);

}

public void addEntity1(QualifiedName arg) {

bindings.addVariable("entity1",arg);

}

public void addAssocid(QualifiedName arg) {

bindings.addVariable("assocId",arg);

}

public void addEntity1(QualifiedName arg) {

bindings.addAttribute("entity1",arg);

}

public void addEntity1(String arg) {

bindings.addAttribute("entity1",arg);

}

public void addTree(QualifiedName arg) {

bindings.addAttribute("tree",arg);

}

public void addTree(String arg) {

bindings.addAttribute("tree",arg);

}

public Bindings getBindings() {

return bindings;

}

public String getTemplate() {

return "src/main/resources/TestTemplate.provn";

}

}

The issue seems to arise because var:entity1 is used both as the entity id as well as an attribute. Since generated methods for adding attributes and variables both have the same naming convention, the resulting BindingsBean will have a duplicate method signature and will not compile.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Flucmoreau%2FProvToolbox%2Fissues%2F160%3Femail_source%3Dnotifications%26email_token%3DAABCXQYBIYBWGTBIFZTLVZLQJJTMBA5CNFSM4IWGWNHKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HLBD4MQ&data=01%7C01%7Cluc.moreau%40kcl.ac.uk%7Ca69e48b7014a4f3d5ce808d7379c81ff%7C8370cf1416f34c16b83c724071654356%7C0&sdata=U9eNUEhU73qk%2BKAhkcwXY3NDQnx10xFRF%2FwAB6fNL5E%3D&reserved=0, or mute the threadhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAABCXQ6SS4AMQG4JN3LMQTDQJJTMBANCNFSM4IWGWNHA&data=01%7C01%7Cluc.moreau%40kcl.ac.uk%7Ca69e48b7014a4f3d5ce808d7379c81ff%7C8370cf1416f34c16b83c724071654356%7C0&sdata=5I2wjZd36EMhvnCCxNPJvXRypSRdSH4%2BcUVaNAw9WEs%3D&reserved=0.

saskiawagenaar commented 5 years ago

Dear Luc,

I'm using the following command: provconvert -infile <input_template_file_name> -location <input_template_directory> -package <output_package_name> -template <name_of_template> -outfile <output_directory>

So if you would save the template provided above as TestTemplate.provn, you could use the following command if you're in the same directory as TestTemplate.provn: provconvert -infile TestTemplate.provn -location . -package testpackage -template TestTemplate -outfile output

The non-compiling binding bean will then be available in output/testpackage/TestTemplateBindingsBean.java

Best regards, Saskia

lucmoreau commented 5 years ago

Thanks Saskia.

I was able to reproduce the problem, and added a quick fix:

In BindingsBeanGenerator, I added the test if (!(allVars.contains(q))) to ensure that the method with that signature is generated once.

for (QualifiedName q: allAtts) { if (!(allVars.contains(q))) builder.addMethod(generateAttMutator(q,QualifiedName.class)); builder.addMethod(generateAttMutator(q,String.class)); }

The fix is currently in the development1_0 branch, and should make it to release shortly.

Regards,

-- Professor Luc Moreau, Head of Department Department of Informatics, King’s College London Strand Campus, Bush House, 30 Aldwych, London, WC2B 4BG. Tel: +44 207 848 6808, web: https://nms.kcl.ac.uk/luc.moreau/https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fnms.kcl.ac.uk%2Fluc.moreau%2F&data=01%7C01%7Cluc.moreau%40kcl.ac.uk%7Cb86b7dc3862647040ff308d70611a6ae%7C8370cf1416f34c16b83c724071654356%7C0&sdata=Xc8kT1rwPqQ3aeCARMIkFoULEy65Bah%2FR3sjk10GUsw%3D&reserved=0

From: Saskia Wagenaar notifications@github.com Reply to: lucmoreau/ProvToolbox reply@reply.github.com Date: Monday, 16 September 2019 at 17:09 To: lucmoreau/ProvToolbox ProvToolbox@noreply.github.com Cc: Luc Moreau luc.moreau@kcl.ac.uk, Comment comment@noreply.github.com Subject: Re: [lucmoreau/ProvToolbox] Generated BindingsBeans does not compile due to duplicate methods (#160)

Dear Luc,

I'm using the following command: provconvert -infile -location -package -template -outfile

So if you would save the template provided above as TestTemplate.provn, you could use the following command if you're in the same directory as TestTemplate.provn: provconvert -infile TestTemplate.provn -location . -package testpackage -template TestTemplate -outfile output

The non-compiling binding bean will then be available in output/testpackage/TestTemplateBindingsBean.java

Best regards, Saskia

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Flucmoreau%2FProvToolbox%2Fissues%2F160%3Femail_source%3Dnotifications%26email_token%3DAABCXQYBMNEBM2MYHS7EMULQJ6VTHA5CNFSM4IWGWNHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6ZVKKY%23issuecomment-531846443&data=01%7C01%7Cluc.moreau%40kcl.ac.uk%7C0381588b414f4873cb1808d73ac03e0f%7C8370cf1416f34c16b83c724071654356%7C0&sdata=ThlJfRoRoMxkUwQx4fgcWhWc8tPw3rtWaVV42mfaKCU%3D&reserved=0, or mute the threadhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAABCXQ55XAM2BRKOC7OW5N3QJ6VTHANCNFSM4IWGWNHA&data=01%7C01%7Cluc.moreau%40kcl.ac.uk%7C0381588b414f4873cb1808d73ac03e0f%7C8370cf1416f34c16b83c724071654356%7C0&sdata=z2fqUSbLgvFSJ9A81iwjGlUUxvb2KAMIqbKkk2is5LM%3D&reserved=0.

lucmoreau commented 5 years ago

And a further point: if it is challenging for you to modify the ProvToolbox source code and rebuild from source, you may want to use a workaround, in which you introduce a different variable name in the template for the variable in attribute position, but the bindings give it the same value as the original variable .

Best regards,

-- Professor Luc Moreau, Head of Department Department of Informatics, King’s College London Strand Campus, Bush House, 30 Aldwych, London, WC2B 4BG. Tel: +44 207 848 6808, web: https://nms.kcl.ac.uk/luc.moreau/https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fnms.kcl.ac.uk%2Fluc.moreau%2F&data=01%7C01%7Cluc.moreau%40kcl.ac.uk%7Cb86b7dc3862647040ff308d70611a6ae%7C8370cf1416f34c16b83c724071654356%7C0&sdata=Xc8kT1rwPqQ3aeCARMIkFoULEy65Bah%2FR3sjk10GUsw%3D&reserved=0

From: Luc Moreau luc.moreau@kcl.ac.uk Date: Wednesday, 2 October 2019 at 07:24 To: lucmoreau/ProvToolbox reply@reply.github.com, lucmoreau/ProvToolbox ProvToolbox@noreply.github.com Cc: Comment comment@noreply.github.com, Luc Moreau luc.moreau@kcl.ac.uk Subject: Re: [lucmoreau/ProvToolbox] Generated BindingsBeans does not compile due to duplicate methods (#160)

Thanks Saskia.

I was able to reproduce the problem, and added a quick fix:

In BindingsBeanGenerator, I added the test if (!(allVars.contains(q))) to ensure that the method with that signature is generated once.

for (QualifiedName q: allAtts) { if (!(allVars.contains(q))) builder.addMethod(generateAttMutator(q,QualifiedName.class)); builder.addMethod(generateAttMutator(q,String.class)); }

The fix is currently in the development1_0 branch, and should make it to release shortly.

Regards,

-- Professor Luc Moreau, Head of Department Department of Informatics, King’s College London Strand Campus, Bush House, 30 Aldwych, London, WC2B 4BG. Tel: +44 207 848 6808, web: https://nms.kcl.ac.uk/luc.moreau/https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fnms.kcl.ac.uk%2Fluc.moreau%2F&data=01%7C01%7Cluc.moreau%40kcl.ac.uk%7C7966f61b37954de2fc9b08d747011c4b%7C8370cf1416f34c16b83c724071654356%7C0&sdata=t%2BO9y%2BGybmTel90gEjEWURWFB4EYE0OwbDozqkx2OUE%3D&reserved=0

From: Saskia Wagenaar notifications@github.com Reply to: lucmoreau/ProvToolbox reply@reply.github.com Date: Monday, 16 September 2019 at 17:09 To: lucmoreau/ProvToolbox ProvToolbox@noreply.github.com Cc: Luc Moreau luc.moreau@kcl.ac.uk, Comment comment@noreply.github.com Subject: Re: [lucmoreau/ProvToolbox] Generated BindingsBeans does not compile due to duplicate methods (#160)

Dear Luc,

I'm using the following command: provconvert -infile -location -package -template -outfile

So if you would save the template provided above as TestTemplate.provn, you could use the following command if you're in the same directory as TestTemplate.provn: provconvert -infile TestTemplate.provn -location . -package testpackage -template TestTemplate -outfile output

The non-compiling binding bean will then be available in output/testpackage/TestTemplateBindingsBean.java

Best regards, Saskia

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Flucmoreau%2FProvToolbox%2Fissues%2F160%3Femail_source%3Dnotifications%26email_token%3DAABCXQYBMNEBM2MYHS7EMULQJ6VTHA5CNFSM4IWGWNHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6ZVKKY%23issuecomment-531846443&data=01%7C01%7Cluc.moreau%40kcl.ac.uk%7C7966f61b37954de2fc9b08d747011c4b%7C8370cf1416f34c16b83c724071654356%7C0&sdata=XYFX64vFdRaobilQxo2QTEr845mM90Pi2jxQO1adeZY%3D&reserved=0, or mute the threadhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAABCXQ55XAM2BRKOC7OW5N3QJ6VTHANCNFSM4IWGWNHA&data=01%7C01%7Cluc.moreau%40kcl.ac.uk%7C7966f61b37954de2fc9b08d747011c4b%7C8370cf1416f34c16b83c724071654356%7C0&sdata=BY%2Bg53LtrsVdeo5CYzXn8TbOUcTKelgN%2F%2FunxEwT2q8%3D&reserved=0.