You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@joshua.apache.org by maxthomas <gi...@git.apache.org> on 2016/08/18 19:14:06 UTC

[GitHub] incubator-joshua pull request #42: Fix various issues related to resources, ...

GitHub user maxthomas opened a pull request:

    https://github.com/apache/incubator-joshua/pull/42

    Fix various issues related to resources, warnings, and copy-pasted code.

    I didn't make an issue for this, because it hits on a lot of topics that would be tough to summarize in one issue. But, let me know if you'd like me to do so. 
    
    The gist of this commit is code cleanup. Resource leaks are closed, warnings are resolved, and the beginning of refactoring the 10K lines of copy/pasted code throughout MERT, MIRA, etc. was started. 
    
    I plan on working on this further on the 7 branch. But, because many resources weren't being closed explicitly (I found the finalize override in LineReader __extremely__ questionable), I figured I'd submit this on master right away. Feel free to ignore/postpone/whatever

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/maxthomas/incubator-joshua fix-warnings-resources

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-joshua/pull/42.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #42
    
----
commit 980f735853a9403823501a66ff857e0c5763ae52
Author: max thomas <ma...@maxthomas.io>
Date:   2016-08-18T19:04:52Z

    Fix a number of issues:
    - Reader now implements autocloseable
    - Close various leaks from LineReader
    - LineReader no longer implements custom finalize(). Resources should be
      explicitly closed when no longer needed. The compiler helps with this.
    - Start refactoring copy/pasted code into a new type: ExistingUTF8EncodedTextFile.
      There is so much use of text files that this should really have
      its own type.
    - Fix warnings about unused fields, unused methods
    - Delete some old/legacy/unused classes

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by maxthomas <gi...@git.apache.org>.
Github user maxthomas commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    Either way is fine: do what's best for your schedule/release. I'm happy to rebase off of 7. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua pull request #42: Fix various issues related to resources, ...

Posted by maxthomas <gi...@git.apache.org>.
Github user maxthomas commented on a diff in the pull request:

    https://github.com/apache/incubator-joshua/pull/42#discussion_r76825646
  
    --- Diff: src/main/java/org/apache/joshua/decoder/ff/lm/buildin_lm/TrieLM.java ---
    @@ -264,66 +215,65 @@ public static void main(String[] args) throws IOException {
         int n = Integer.valueOf(args[2]);
         LOG.info("N-gram order will be {}", n);
     
    -    Scanner scanner = new Scanner(new File(args[1]));
    +    try (Scanner scanner = new Scanner(new File(args[1]));) {
    --- End diff --
    
    I personally prefer the semicolon:
    
    * it's necessary if other statements/resources are added to the autoclose block
    * it's easier to determine the actual method call when there are many parens towards the end
    
    but I don't mind either way. 
    
    What would be nice is a commit that applies the format across the entire project. A ton of lines have trailing whitespace or tabs or whatever. I'n going to file an issue on this. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua pull request #42: Fix various issues related to resources, ...

Posted by KellenSunderland <gi...@git.apache.org>.
Github user KellenSunderland commented on a diff in the pull request:

    https://github.com/apache/incubator-joshua/pull/42#discussion_r76822076
  
    --- Diff: src/main/java/org/apache/joshua/decoder/ff/lm/buildin_lm/TrieLM.java ---
    @@ -188,62 +188,13 @@ public TrieLM(ArpaFile arpaFile) throws FileNotFoundException {
     
     
       @Override
    -  protected double logProbabilityOfBackoffState_helper(
    -      int[] ngram, int order, int qtyAdditionalBackoffWeight
    -      ) {
    +  protected double logProbabilityOfBackoffState_helper(int[] ngram, int order, int qtyAdditionalBackoffWeight) {
         throw new UnsupportedOperationException("probabilityOfBackoffState_helper undefined for TrieLM");
       }
     
       @Override
       protected float ngramLogProbability_helper(int[] ngram, int order) {
    -
    -//    float logProb = (float) -JoshuaConfiguration.lm_ceiling_cost;//Float.NEGATIVE_INFINITY; // log(0.0f)
    -    float backoff = 0.0f; // log(1.0f)
    -
    -    int i = ngram.length - 1;
    -    int word = ngram[i];
    -    i -= 1;
    -
    -    int nodeID = ROOT_NODE_ID;
    -
    -    while (true) {
    -
    -      {
    -        long key = Bits.encodeAsLong(nodeID, word);
    -        if (logProbs.containsKey(key)) {
    -//          logProb = logProbs.get(key);
    -          backoff = 0.0f; // log(0.0f)
    -        }
    -      }
    -
    -      if (i < 0) {
    -        break;
    -      }
    -
    -      {
    -        long key = Bits.encodeAsLong(nodeID, ngram[i]);
    -
    -        if (children.containsKey(key)) {
    -          nodeID = children.get(key);
    -
    -          backoff += backoffs.get(nodeID);
    -
    -          i -= 1;
    -
    -        } else {
    -          break;
    -        }
    -      }
    -
    -    }
    -
    -//    double result = logProb + backoff;
    -//    if (result < -JoshuaConfiguration.lm_ceiling_cost) {
    -//      result = -JoshuaConfiguration.lm_ceiling_cost;
    -//    }
    -//
    -//    return result;
    -    return (Float) null;
    +    throw new UnsupportedOperationException();
    --- End diff --
    
    Good change, but I'd just like to note this is an example of https://en.wikipedia.org/wiki/Interface_segregation_principle that we should think about cleaning up one day.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by maxthomas <gi...@git.apache.org>.
Github user maxthomas commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    just rebased off latest master


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua pull request #42: Fix various issues related to resources, ...

Posted by KellenSunderland <gi...@git.apache.org>.
Github user KellenSunderland commented on a diff in the pull request:

    https://github.com/apache/incubator-joshua/pull/42#discussion_r76820408
  
    --- Diff: src/main/java/org/apache/joshua/decoder/Translation.java ---
    @@ -44,8 +43,13 @@
     /**
      * This class represents translated input objects (sentences or lattices). It is aware of the source
      * sentence and id and contains the decoded hypergraph. Translation objects are returned by
    +<<<<<<< HEAD
    --- End diff --
    
    Conflicts still present in this file.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by mjpost <gi...@git.apache.org>.
Github user mjpost commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    Yes, please merge master into 7!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by mjpost <gi...@git.apache.org>.
Github user mjpost commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    This actually looks really great, but I'm worried about the complexity of merging this with the 7, which moves every file and changed a bunch with refactoring the feature function interface. How much work went into this, and how hard would it be to repeat it?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Re: [GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by Matt Post <po...@cs.jhu.edu>.
Rebasing changes the history, so I think you can't do that with repos that have been pushed, right? In which case merge...

matt (from my phone)

> On Aug 30, 2016, at 3:41 PM, maxthomas <gi...@git.apache.org> wrote:
> 
> Github user maxthomas commented on the issue:
> 
>    https://github.com/apache/incubator-joshua/pull/42
> 
>    do you want me to rebase off master, or merge? 
> 
> 
> ---
> If your project is set up for it, you can reply to this email and have your
> reply appear on GitHub as well. If your project does not have this feature
> enabled and wishes so, or if the feature is enabled but not working, please
> contact infrastructure at infrastructure@apache.org or file a JIRA ticket
> with INFRA.
> ---


[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by maxthomas <gi...@git.apache.org>.
Github user maxthomas commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    do you want me to rebase off master, or merge? 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by maxthomas <gi...@git.apache.org>.
Github user maxthomas commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    sure, that conflict comment should be fixed. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by mjpost <gi...@git.apache.org>.
Github user mjpost commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    So am I correct that this is ready to merge into master?
    
    And @maxthomas, you think you can merge this into 7?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by maxthomas <gi...@git.apache.org>.
Github user maxthomas commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    yep, this is ready if you are ready!
    
    i'm happy to merge this into 7. would you like me to do that after this is in master? just let me know. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua pull request #42: Fix various issues related to resources, ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-joshua/pull/42


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by maxthomas <gi...@git.apache.org>.
Github user maxthomas commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    see #49 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by mjpost <gi...@git.apache.org>.
Github user mjpost commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    So, @maxthomas�\u2014�what do you think about either of the following:
    
    - You (a) remerge master into this, and then (b) merge master into 7
    - Skip (a) and just rework this against the 7 branch?
    
    I think this is good to have in the codebase, but I'm not sure that it's critical to have for the 6.1 release. But if it's not too much work to do both, I'm not against trying.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua pull request #42: Fix various issues related to resources, ...

Posted by KellenSunderland <gi...@git.apache.org>.
Github user KellenSunderland commented on a diff in the pull request:

    https://github.com/apache/incubator-joshua/pull/42#discussion_r76822903
  
    --- Diff: src/main/java/org/apache/joshua/decoder/ff/lm/buildin_lm/TrieLM.java ---
    @@ -264,66 +215,65 @@ public static void main(String[] args) throws IOException {
         int n = Integer.valueOf(args[2]);
         LOG.info("N-gram order will be {}", n);
     
    -    Scanner scanner = new Scanner(new File(args[1]));
    +    try (Scanner scanner = new Scanner(new File(args[1]));) {
    --- End diff --
    
    Nitpick: would it be ok to remove the semicolon from the autocloseable lines?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua pull request #42: Fix various issues related to resources, ...

Posted by KellenSunderland <gi...@git.apache.org>.
Github user KellenSunderland commented on a diff in the pull request:

    https://github.com/apache/incubator-joshua/pull/42#discussion_r76827028
  
    --- Diff: src/main/java/org/apache/joshua/decoder/ff/lm/buildin_lm/TrieLM.java ---
    @@ -264,66 +215,65 @@ public static void main(String[] args) throws IOException {
         int n = Integer.valueOf(args[2]);
         LOG.info("N-gram order will be {}", n);
     
    -    Scanner scanner = new Scanner(new File(args[1]));
    +    try (Scanner scanner = new Scanner(new File(args[1]));) {
    --- End diff --
    
    You've convinced me.  I'll see if I can do semicolons in the future to keep it consistent.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by mjpost <gi...@git.apache.org>.
Github user mjpost commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    All right; maybe hold off and let me finish and merge in one other large-ish commit, and then I'll take a look at this. It's possible it will be easier than I anticipate.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-joshua issue #42: Fix various issues related to resources, warning...

Posted by KellenSunderland <gi...@git.apache.org>.
Github user KellenSunderland commented on the issue:

    https://github.com/apache/incubator-joshua/pull/42
  
    Wow Max, great update.  Many thanks!  I total agree on the questionable finalizes.  The code cleanup in general looks great, lots of dead code removed there.
    
    As mentioned above there are some conflicts in one commented file, if you could fix those it'd be great.  Otherwise looks good to me \U0001f44d .



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---