NaiveText 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bffe658cb690c71d28fd693588064745e9640c8
4
- data.tar.gz: 61ab533db552448d60e2db369b30894d80ea4db1
3
+ metadata.gz: ec519a11d1de21e62b71bb470ef0097ed62910f8
4
+ data.tar.gz: bc96077d8ed6fa7890692466a2954425a8719540
5
5
  SHA512:
6
- metadata.gz: 93e4e8662da0b13d0f6eb1b92c3138d46d460b3011fc1fbf051680a8e49affe4560aef19b89ffca8ad37d2b24be505e31819763b24912d479b8aa430b82af965
7
- data.tar.gz: 61aa7b9f67a81165e4a1910e4b212c00e2fe1bb1c27c7f86d2673500c73793d42f4f06d4ca28946b770417d81c2bb9265ef327de5549c98af7e6625939847f76
6
+ metadata.gz: 15446a47f72ed08af4c32924f5b7b246878bdc184f21a9616259a346c010baba9f25ca426a22f60bb29ff5d9e94b9cd311c41221fdb728542d794fa7777f5c01
7
+ data.tar.gz: bfb9e832ddd6a8f3f7aebc8cc47c949f7aac93d1a718d6db461c827e247575c937ddf4ae23be3b89d6d2c0617b93d8a5f5ed1a830fc59b1f440c0bbd770e1e3b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [0.5.1] - 2015-11-21
6
+ ### Added
7
+ - Added optional default category. This category will be returned from NaiveText.build if the algorithm can't find a match with the existing text examples. Default value is NullCategory.
8
+
5
9
  ## [0.5.0] - 2015-11-06
6
10
  ### Added
7
11
  - Added optional weighting to categories
@@ -28,4 +32,5 @@ This project adheres to [Semantic Versioning](http://semver.org/).
28
32
 
29
33
 
30
34
  [Unreleased]: https://github.com/RicciFlowing/NaiveText/compare/v0.4.0...HEAD
31
- [0.4.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.1.0...v0.4.0
35
+ [0.5.0]: https://github.com/RicciFlowing/NaiveText/compare/v0.1.0...v0.5.0
36
+ [0.4.0]: https://github.com/RicciFlowing/NaiveText/compare/v0.1.0...v0.4.0
@@ -1,8 +1,11 @@
1
1
  class Categories
2
2
  include Enumerable
3
3
 
4
+ attr_reader :default
5
+
4
6
  def initialize(args)
5
7
  @categories = args[:categories] || []
8
+ @default = args[:default] || NullCategory.new
6
9
  end
7
10
 
8
11
  def p_apriori(category)
@@ -1,6 +1,7 @@
1
1
  class CategoriesFactory
2
2
  def self.build(config)
3
3
  categories = []
4
+ default = nil
4
5
  if config.is_a?(Array)
5
6
  puts "The format [{name: name_of_category, path: path_to_trainings_data}] is deprecated and will be removed in future versions. Use the following arguments instead: categories: [name: 'the name', examples:'An example']"
6
7
  config.each do |category_config|
@@ -20,13 +21,17 @@ class CategoriesFactory
20
21
  config[:categories].each do |category_config|
21
22
  begin
22
23
  group = ExamplesGroup.new(examples: category_config[:examples])
23
- categories << Category.new(name: category_config[:name], examples: group, weight: category_config[:weight])
24
+ category = Category.new(name: category_config[:name], examples: group, weight: category_config[:weight])
25
+ categories << category
26
+ if category_config[:name] == config[:default]
27
+ default = category
28
+ end
24
29
  rescue
25
30
  puts "You haven't provided trainingsdata for the category" + category_config[:name]
26
31
  puts "This category was not created."
27
32
  end
28
33
  end
29
- Categories.new(categories: categories)
34
+ Categories.new(categories: categories, default: default )
30
35
  end
31
36
  end
32
37
  end
@@ -9,7 +9,7 @@ class Category
9
9
  @examples = args[:examples]
10
10
  @weight = args[:weight] || 1
11
11
  @id = @@id_counter
12
-
12
+
13
13
  @@id_counter += 1
14
14
  end
15
15
 
@@ -40,7 +40,7 @@ class ProbabilityCollection
40
40
  id = @probabilities.find_index(@probabilities.max)
41
41
  @categories.find {|category| category.id == id}
42
42
  else
43
- NullCategory.new
43
+ @categories.default
44
44
  end
45
45
  end
46
46
 
@@ -1,3 +1,3 @@
1
1
  module NaiveText
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: NaiveText
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - RicciFlowing
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-06 00:00:00.000000000 Z
11
+ date: 2015-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler