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

feature/string-attributes: fixed issue#12 #13

Merged
merged 4 commits into from Dec 4, 2016
Merged

feature/string-attributes: fixed issue#12 #13

merged 4 commits into from Dec 4, 2016

Conversation

kcning
Copy link
Contributor

@kcning kcning commented Dec 2, 2016

Hi, I finished the missing part! #12

Copy link
Owner

@paulgoetze paulgoetze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks! Looks great.

Would you mind adding tests for the #internal_value_of for string values here:
https://github.com/kcning/weka-jruby/blob/feature/string-attributes-issue-12/spec/core/attribute_spec.rb#L67?

Let me know if you need any help (I could also take over the testing part, in case you are short of time).

# else we add the value to the range and return its new index
add_string_value(value.to_s)
end
end
Copy link
Owner

@paulgoetze paulgoetze Dec 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the string handling could be moved into a separate private method, in order to keep #internal_value_of as concise as possible. Maybe sth. like index_of_string(value)?

With this, we could have a one-liner as for the other types (I'd use the return here as well, even if it is not necessary):

return index_of_string(value) if string?

I would also avoid assignments in if clauses and would rather do it before with a fully readable name, like:

index = index_of_value(value.to_s)

if index == -1
  # ...
else
 # ...
end

The comments could then be the method’s comment and move out of the body (Should work, right? The new method should be short enough, to get what it refers to)

Could you make these changes? Then we are good to go!

Attribute#add_string_value() should not be called inside
Attribute#internal_value_of(). The method call is moved into
Instances#instance_from().
@kcning
Copy link
Contributor Author

kcning commented Dec 3, 2016

Oke now we have the spec. Can you please check?

else
value
end
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right–adding the string value should not be done in the Attribute’s #internal_value_for but already during the creation of the instance. Nice catch!

@paulgoetze
Copy link
Owner

Tests are still missing for the implementation of adding string values–all tests pass if you comment out the added code (https://github.com/paulgoetze/weka-jruby/pull/13/files#diff-bb64f986c10a4d064a282d726d7b6c77R232).
Anyway, I also found some other missing things to fully support string attributes.

So, I will just go ahead and merge this and do the rest of the changes in #12 (I think the easiest is to add a string attribute to the test dataset files to cover all string cases in the tests as well).

Thanks again for your contributions!

@paulgoetze paulgoetze merged commit a88ee4f into paulgoetze:feature/string-attributes Dec 4, 2016
@paulgoetze paulgoetze mentioned this pull request Dec 4, 2016
3 tasks
@kcning
Copy link
Contributor Author

kcning commented Dec 4, 2016

Thanks! I'm using the gem for some string data mining so I can add the use cases to the spec. If I come across the missing methods for string attributes I can also add it. (What are the missing things, actually?)

@kcning kcning deleted the feature/string-attributes-issue-12 branch December 4, 2016 17:49
@paulgoetze
Copy link
Owner

paulgoetze commented Dec 4, 2016

Nice, then go ahead, I really appreciate some help here!

One missing thing I came across is DenseInstance#value_from needs string handling, too:

def value_from(value, index)

I also added some todos to #12.

I will have a look and let you know, when I spot other stuff.

One other thing: could you make sure your code is compliant with default Rubocop recommendations? I used it for this project, yet need to add a hint to the Readme.

Further discussion can happen either in #12 or a new PR. Thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants