search-intent-mix 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 051d3b41b40c26a5522b54dee76f8d42bf48dba2ca234698073172bc6c5a4025
4
+ data.tar.gz: 820480aa27fe2b80e2d79e3a2a016a72d146cba2d41318f5c65ff96320393c0b
5
+ SHA512:
6
+ metadata.gz: 7381ed9465e49e139cd9396765629553fc8a2d429242b60172a38ef06d84c91baac803ff37d2d81268e18944bc72fa1eb820f7dd9c5e2166c40820229ee65fc1
7
+ data.tar.gz: 63f0f87ce0725b49c07049dbf42974319bee1ac4a7f7907991da1bf3cb5036918a18f61bf8b6ca97c1bb4d4f8d8e3eeef460ac3821e97599610ec4ff5cd64961
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OneGTMLab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # search-intent-mix
2
+
3
+ Ruby command line tool and library. Give it a CSV of keywords where you have already written down the search intent of each one and its volume. It counts keywords and volume per intent, shows each intent's share of keywords and of volume, the average volume per keyword, the top 3 keywords of each intent, and which intent has the most keywords and the most volume.
4
+
5
+ Part of the [OneGTMLab](https://www.onegtmlab.dev) free GTM tools. Background on the idea: [search intent](https://www.onegtmlab.dev/glossary/search-intent).
6
+
7
+ ## Install
8
+
9
+ ```
10
+ gem install search-intent-mix
11
+ ```
12
+
13
+ ## Use
14
+
15
+ CSV columns: keyword, intent, volume. The intent is a label you assigned by hand or with your own tool (for example informational, commercial, transactional, navigational); the tool does no classification and only counts your labels. Labels are trimmed and compared ignoring upper and lower case, and the first spelling seen is shown. Volume is a whole number of 0 or more from your own keyword tool; an empty volume counts as 0. A keyword that appears more than once (ignoring case) is counted once with its highest volume (the first row wins a tie), and the number merged is printed. Intents are sorted by volume, highest first, then by name; the top keywords of an intent are sorted by volume, then by keyword. When two intents are equal on keywords or on volume the output says tie. All percentages are rounded half up to 1 decimal, and averages likewise. Option --focus LABEL adds one line with the share of volume and of keywords on that label (ignoring case); a label that is not in the file shows 0.0%. A missing file, a missing column, a bad volume or an empty intent (the row is named), a bad option or a CSV with no rows stops the run with an error and a non-zero exit code.
16
+
17
+ ```
18
+ $ ruby bin/search-intent-mix sample.csv --focus commercial
19
+ keywords: 10
20
+ total volume: 6500
21
+ duplicate keywords merged (highest volume kept): 1
22
+
23
+ intent keywords kw share volume vol share avg volume
24
+ Commercial 3 30.0% 3200 49.2% 1066.7
25
+ Informational 4 40.0% 2600 40.0% 650.0
26
+ Transactional 2 20.0% 450 6.9% 225.0
27
+ Navigational 1 10.0% 250 3.8% 250.0
28
+
29
+ top keywords by volume
30
+ Commercial
31
+ best alpha tools 2000
32
+ beta vs alpha 700
33
+ alpha tool pricing 500
34
+ Informational
35
+ alpha tool guide 1200
36
+ what is beta 800
37
+ beta setup steps 600
38
+ Transactional
39
+ buy alpha tool 300
40
+ buy beta plan 150
41
+ Navigational
42
+ alpha tool login 250
43
+
44
+ most keywords: Informational (4)
45
+ most volume: Commercial (3200)
46
+
47
+ focus Commercial: 49.2% of volume (3200 of 6500), 30.0% of keywords (3 of 10)
48
+ ```
49
+
50
+ ## Test
51
+
52
+ ```
53
+ ruby test/run.rb
54
+ ```
55
+
56
+ Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/search_intent_mix'
5
+
6
+ if ARGV.empty? || ARGV.include?('-h') || ARGV.include?('--help')
7
+ warn "usage: search-intent-mix keywords.csv [--focus LABEL]\n" \
8
+ "CSV columns: keyword, intent, volume. More: https://www.onegtmlab.dev/glossary/search-intent"
9
+ exit 2
10
+ end
11
+
12
+ begin
13
+ path, focus = SearchIntentMix.parse_args(ARGV)
14
+ rows, merged = SearchIntentMix.from_csv(File.read(path))
15
+ print SearchIntentMix.render(SearchIntentMix.analyze(rows, merged, focus: focus))
16
+ rescue ArgumentError, Errno::ENOENT, Errno::EISDIR, CSV::MalformedCSVError => e
17
+ abort "error: #{e.message}"
18
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+
5
+ # Count the search intent labels YOU assigned to a keyword list and show how keywords and volume split across them.
6
+ # The tool does no classification: it only counts your labels.
7
+ module SearchIntentMix
8
+ Row = Struct.new(:keyword, :intent, :volume, keyword_init: true)
9
+
10
+ # Percentage of n in d, rounded half up to 1 decimal. 0.0 when d is 0.
11
+ def self.pct(n, d)
12
+ return 0.0 if d.zero?
13
+
14
+ Rational(n * 100, d).round(1).to_f
15
+ end
16
+
17
+ # Average rounded half up to 1 decimal.
18
+ def self.avg(n, d)
19
+ return 0.0 if d.zero?
20
+
21
+ Rational(n, d).round(1).to_f
22
+ end
23
+
24
+ def self.parse_volume(raw, line)
25
+ s = raw.to_s.strip
26
+ return 0 if s.empty?
27
+ raise ArgumentError, "row #{line}: bad volume #{s.inspect}, expected a whole number of 0 or more" unless s.match?(/\A\d+\z/)
28
+
29
+ s.to_i
30
+ end
31
+
32
+ # Returns [rows, merged_duplicates]. Duplicate keywords (case-insensitive, trimmed): the row with the highest volume is kept
33
+ # (the first one on a tie) and the others are counted.
34
+ def self.from_csv(text)
35
+ table = CSV.parse(text.sub(/\A/, ''), headers: true, header_converters: ->(h) { h.to_s.strip.downcase })
36
+ missing = %w[keyword intent volume] - table.headers.compact
37
+ raise ArgumentError, "missing column(s): #{missing.join(', ')}" unless missing.empty?
38
+ raise ArgumentError, 'no rows in the CSV' if table.empty?
39
+
40
+ kept = {}
41
+ merged = 0
42
+ table.each_with_index do |r, i|
43
+ line = i + 2
44
+ keyword = r['keyword'].to_s.strip
45
+ intent = r['intent'].to_s.strip
46
+ raise ArgumentError, "row #{line}: empty keyword" if keyword.empty?
47
+ raise ArgumentError, "row #{line}: empty intent for #{keyword.inspect}" if intent.empty?
48
+
49
+ row = Row.new(keyword: keyword, intent: intent, volume: parse_volume(r['volume'], line))
50
+ key = keyword.downcase
51
+ if kept.key?(key)
52
+ merged += 1
53
+ kept[key] = row if row.volume > kept[key].volume
54
+ else
55
+ kept[key] = row
56
+ end
57
+ end
58
+ [kept.values, merged]
59
+ end
60
+
61
+ # Intent labels are grouped case-insensitively; the first spelling seen is displayed.
62
+ def self.analyze(rows, merged = 0, focus: nil)
63
+ groups = {}
64
+ rows.each do |r|
65
+ g = (groups[r.intent.downcase] ||= { label: r.intent, rows: [] })
66
+ g[:rows] << r
67
+ end
68
+ total_kw = rows.size
69
+ total_vol = rows.sum(&:volume)
70
+ intents = groups.values.map do |g|
71
+ vol = g[:rows].sum(&:volume)
72
+ { label: g[:label], keywords: g[:rows].size, keyword_share: pct(g[:rows].size, total_kw), volume: vol,
73
+ volume_share: pct(vol, total_vol), average: avg(vol, g[:rows].size),
74
+ top: g[:rows].sort_by { |r| [-r.volume, r.keyword.downcase, r.keyword] }.first(3).map { |r| [r.keyword, r.volume] } }
75
+ end
76
+ intents.sort_by! { |i| [-i[:volume], i[:label].downcase, i[:label]] }
77
+ result = { keywords: total_kw, total_volume: total_vol, merged: merged, intents: intents,
78
+ most_keywords: leaders(intents, :keywords), most_volume: leaders(intents, :volume) }
79
+ if focus
80
+ g = intents.find { |i| i[:label].downcase == focus.downcase }
81
+ result[:focus] = { label: g ? g[:label] : focus, found: !g.nil?, keywords: g ? g[:keywords] : 0, volume: g ? g[:volume] : 0,
82
+ volume_share: g ? g[:volume_share] : 0.0, keyword_share: g ? g[:keyword_share] : 0.0 }
83
+ end
84
+ result
85
+ end
86
+
87
+ def self.leaders(intents, key)
88
+ best = intents.map { |i| i[key] }.max
89
+ { labels: intents.select { |i| i[key] == best }.map { |i| i[:label] }.sort_by { |l| [l.downcase, l] }, value: best }
90
+ end
91
+
92
+ def self.leader_text(l)
93
+ l[:labels].size > 1 ? "tie (#{l[:labels].join(', ')}), #{l[:value]} each" : "#{l[:labels].first} (#{l[:value]})"
94
+ end
95
+
96
+ def self.render(result)
97
+ out = +"keywords: #{result[:keywords]}\ntotal volume: #{result[:total_volume]}\n"
98
+ out << "duplicate keywords merged (highest volume kept): #{result[:merged]}\n"
99
+ out << "\n"
100
+ out << format("%-14s %8s %9s %8s %10s %11s\n", 'intent', 'keywords', 'kw share', 'volume', 'vol share', 'avg volume')
101
+ result[:intents].each do |i|
102
+ out << format("%-14s %8d %8.1f%% %8d %9.1f%% %11.1f\n", i[:label], i[:keywords], i[:keyword_share], i[:volume],
103
+ i[:volume_share], i[:average])
104
+ end
105
+ out << "\ntop keywords by volume\n"
106
+ result[:intents].each do |i|
107
+ out << "#{i[:label]}\n"
108
+ i[:top].each { |k, v| out << format(" %-24s %6d\n", k, v) }
109
+ end
110
+ out << "\nmost keywords: #{leader_text(result[:most_keywords])}\n"
111
+ out << "most volume: #{leader_text(result[:most_volume])}\n"
112
+ if (f = result[:focus])
113
+ out << "\nfocus #{f[:label]}: "
114
+ if f[:found]
115
+ out << "#{f[:volume_share].round(1)}% of volume (#{f[:volume]} of #{result[:total_volume]}), " \
116
+ "#{f[:keyword_share].round(1)}% of keywords (#{f[:keywords]} of #{result[:keywords]})\n"
117
+ else
118
+ out << "no keyword in the file has this intent label, 0.0% of volume\n"
119
+ end
120
+ end
121
+ out
122
+ end
123
+
124
+ # Returns [path, focus]; raises ArgumentError on bad input.
125
+ def self.parse_args(argv)
126
+ args = argv.dup
127
+ path = nil
128
+ focus = nil
129
+ until args.empty?
130
+ arg = args.shift
131
+ case arg
132
+ when '--focus'
133
+ raise ArgumentError, '--focus needs a label' if args.empty?
134
+
135
+ focus = args.shift.to_s.strip
136
+ raise ArgumentError, '--focus needs a non-empty label' if focus.empty?
137
+ when /\A-/ then raise ArgumentError, "unknown option #{arg}"
138
+ else
139
+ raise ArgumentError, "unexpected extra argument #{arg.inspect}" if path
140
+
141
+ path = arg
142
+ end
143
+ end
144
+ raise ArgumentError, 'no CSV file given' unless path
145
+
146
+ [path, focus]
147
+ end
148
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: search-intent-mix
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - OneGTMLab
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: csv
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: "0"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: "0"
28
+ description: "Ruby CLI and library: from a CSV of keywords with an intent label you assigned and a volume, count keywords and volume per intent, show shares, averages and the top keywords of each intent. It does no classification itself. Offline."
29
+ executables:
30
+ - search-intent-mix
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - bin/search-intent-mix
37
+ - lib/search_intent_mix.rb
38
+ homepage: "https://www.onegtmlab.dev/glossary/search-intent"
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ source_code_uri: "https://github.com/jaizendra-netizen/search-intent-mix"
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ -
49
+ - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "2.7"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ -
55
+ - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ requirements: []
59
+ rubygems_version: 4.1.0
60
+ specification_version: 4
61
+ summary: Count the search intent labels you assigned to a keyword list and show the split by keywords and volume
62
+ test_files: []