truth_serum_academic 0.1.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 +7 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/bin/truth_serum +37 -0
- data/lib/truth_serum/result.rb +28 -0
- data/lib/truth_serum/verifier.rb +59 -0
- data/lib/truth_serum/version.rb +5 -0
- data/lib/truth_serum.rb +8 -0
- data/truth_serum.gemspec +27 -0
- metadata +76 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 61567f2d575ced3d37904bc6c64d1c4087b44a545082d13a7ba4dff40bb8a30c
|
|
4
|
+
data.tar.gz: c2a4782c0349682575993feaea7de717409ce8cbbea7baf348b629d9e9d8a097
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 00ebb740e006b66f5b83c25fea94333e06a2dcb155bb46736bbebd18fbda4df786c3792acc36709812240d5df7cff48e3ad7e721f5795c4cc83c6a6866a95076
|
|
7
|
+
data.tar.gz: c25c9d9db9092e94db7725e82ec6379196814b6e3fceaf8dccc79756b1c51be51ab9a84223280fa0f21864a5272d419621b21dc79ff74f97026c34ab5cdf70f7
|
data/bin/console
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "truth_serum"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
require "irb"
|
|
11
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bin/truth_serum
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# 1. SETUP LOAD PATH
|
|
4
|
+
# This line is crucial for development. It tells Ruby to look in your local 'lib'
|
|
5
|
+
# folder for the code, so you don't have to install the gem to test it.
|
|
6
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
|
7
|
+
|
|
8
|
+
require 'truth_serum'
|
|
9
|
+
|
|
10
|
+
# 2. CAPTURE INPUT
|
|
11
|
+
# ARGV is an array containing the arguments passed in the command line.
|
|
12
|
+
input_text = ARGV[0]
|
|
13
|
+
|
|
14
|
+
# Check if the user actually typed something
|
|
15
|
+
if input_text.nil? || input_text.strip.empty?
|
|
16
|
+
puts "Usage: truth_serum \"<citation text>\""
|
|
17
|
+
exit
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
puts "🔍 Analyzing citation..."
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# 3. RUN VERIFICATION
|
|
24
|
+
# We wrap the input in brackets [] because your Verifier expects a list.
|
|
25
|
+
results = TruthSerum::Verifier.check_list([input_text])
|
|
26
|
+
result = results.first
|
|
27
|
+
|
|
28
|
+
# 4. PRINT OUTPUT
|
|
29
|
+
# This uses the nice helper methods from your new Result object.
|
|
30
|
+
puts "---------------------------------------------------"
|
|
31
|
+
if result.verified?
|
|
32
|
+
puts "✅ REAL (#{result.score})"
|
|
33
|
+
else
|
|
34
|
+
puts "❌ FAKE (#{result.score})"
|
|
35
|
+
end
|
|
36
|
+
puts " #{result.text}"
|
|
37
|
+
puts "---------------------------------------------------"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module TruthSerum
|
|
2
|
+
class Result
|
|
3
|
+
attr_reader :text, :score, :status, :metadata
|
|
4
|
+
|
|
5
|
+
def initialize(text:, score:, status:, metadata: {})
|
|
6
|
+
@text = text
|
|
7
|
+
@score = score
|
|
8
|
+
@status = status
|
|
9
|
+
@metadata = metadata
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Helper method: Returns true if the status is :real
|
|
13
|
+
# This is much cleaner than checking `if hash[:status] == :real`
|
|
14
|
+
def verified?
|
|
15
|
+
@status == :real
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Helper method: Returns true if the status is :fake
|
|
19
|
+
def fake?
|
|
20
|
+
@status == :fake
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# A friendly string representation for debugging
|
|
24
|
+
def to_s
|
|
25
|
+
"[#{@status.upcase}] Score: #{@score} | #{@text[0..30]}..."
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
require_relative 'result'
|
|
3
|
+
|
|
4
|
+
module TruthSerum
|
|
5
|
+
class Verifier
|
|
6
|
+
BASE_URL = "https://api.crossref.org/works"
|
|
7
|
+
|
|
8
|
+
def self.check_list(list)
|
|
9
|
+
results = []
|
|
10
|
+
|
|
11
|
+
list.each do |citation|
|
|
12
|
+
response = HTTParty.get(BASE_URL, query: {
|
|
13
|
+
"query.bibliographic" => citation,
|
|
14
|
+
"rows" => 1
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
data = response.parsed_response
|
|
18
|
+
items = data.dig("message", "items")
|
|
19
|
+
|
|
20
|
+
status = :fake
|
|
21
|
+
score = 0.0
|
|
22
|
+
|
|
23
|
+
# LOGIC: Check if we found a match AND if it looks similar
|
|
24
|
+
if items && items.any?
|
|
25
|
+
top_match = items.first
|
|
26
|
+
found_title = top_match["title"]&.first || ""
|
|
27
|
+
|
|
28
|
+
# 1. Normalize strings (lowercase, find words 4+ letters long)
|
|
29
|
+
# We ignore small words like "the", "of", "and".
|
|
30
|
+
input_words = citation.downcase.scan(/[a-z]{4,}/)
|
|
31
|
+
found_words = found_title.downcase.scan(/[a-z]{4,}/)
|
|
32
|
+
|
|
33
|
+
# 2. Count common words
|
|
34
|
+
common_words = input_words & found_words
|
|
35
|
+
|
|
36
|
+
# 3. Decision Threshold
|
|
37
|
+
# If they share at least 2 significant words, we assume it's the same paper.
|
|
38
|
+
if common_words.size >= 2
|
|
39
|
+
status = :real
|
|
40
|
+
score = top_match["score"]
|
|
41
|
+
else
|
|
42
|
+
# We found a paper, but the title was too different.
|
|
43
|
+
# (e.g. You searched "Musk Mars" and got "Geology of Mars")
|
|
44
|
+
status = :fake
|
|
45
|
+
score = 0.1 # Low score for mismatch
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
results << TruthSerum::Result.new(
|
|
50
|
+
text: citation,
|
|
51
|
+
score: score,
|
|
52
|
+
status: status
|
|
53
|
+
)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
results
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
data/lib/truth_serum.rb
ADDED
data/truth_serum.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/truth_serum/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "truth_serum_academic"
|
|
7
|
+
spec.version = TruthSerum::VERSION
|
|
8
|
+
spec.authors = ["Nathalie Tasler"]
|
|
9
|
+
spec.email = ["drntasler@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "A citation checker gem"
|
|
12
|
+
spec.description = "A Ruby gem that checks citations against Crossref API."
|
|
13
|
+
spec.license = "MIT"
|
|
14
|
+
spec.required_ruby_version = ">= 3.2.0"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
spec.files = Dir.glob("{bin,lib}/**/*") + ["truth_serum.gemspec"]
|
|
18
|
+
|
|
19
|
+
spec.bindir = "bin"
|
|
20
|
+
spec.executables = ["truth_serum"]
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
# This is the dependency for the API calls
|
|
24
|
+
spec.add_dependency "httparty"
|
|
25
|
+
# Development dependency (You need this to run tests)
|
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: truth_serum_academic
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nathalie Tasler
|
|
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: httparty
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rspec
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '3.0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '3.0'
|
|
40
|
+
description: A Ruby gem that checks citations against Crossref API.
|
|
41
|
+
email:
|
|
42
|
+
- drntasler@gmail.com
|
|
43
|
+
executables:
|
|
44
|
+
- truth_serum
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- bin/console
|
|
49
|
+
- bin/setup
|
|
50
|
+
- bin/truth_serum
|
|
51
|
+
- lib/truth_serum.rb
|
|
52
|
+
- lib/truth_serum/result.rb
|
|
53
|
+
- lib/truth_serum/verifier.rb
|
|
54
|
+
- lib/truth_serum/version.rb
|
|
55
|
+
- truth_serum.gemspec
|
|
56
|
+
licenses:
|
|
57
|
+
- MIT
|
|
58
|
+
metadata: {}
|
|
59
|
+
rdoc_options: []
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: 3.2.0
|
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '0'
|
|
72
|
+
requirements: []
|
|
73
|
+
rubygems_version: 4.0.3
|
|
74
|
+
specification_version: 4
|
|
75
|
+
summary: A citation checker gem
|
|
76
|
+
test_files: []
|