Class: MathMetadata::Article

Inherits:
Entity
  • Object
show all
Defined in:
lib/math_metadata_lookup/article.rb

Instance Method Summary collapse

Methods inherited from Entity

#[], #[]=, #format, #initialize, #method_missing

Constructor Details

This class inherits a constructor from MathMetadata::Entity

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MathMetadata::Entity

Instance Method Details

#==(article) ⇒ Object



5
6
7
# File 'lib/math_metadata_lookup/article.rb', line 5

def ==(article)
  similarity(article) > 0.9
end

#similarity(article) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/math_metadata_lookup/article.rb', line 10

def similarity(article)
  td = MathMetadata.levenshtein_distance @metadata[:title].to_s, article[:title].to_s
  ad = MathMetadata.levenshtein_distance [@metadata[:authors]].flatten.sort.join(";"), [article[:authors]].flatten.sort.join(";")
  yd = MathMetadata.levenshtein_distance @metadata[:year].to_s, article[:year].to_s

  m = []
  m << [td, 2.8] unless @metadata[:title].to_s.empty?
  m << [ad, 1.4] unless [@metadata[:authors]].flatten.join(";").empty?
  m << [yd, 1.0] unless @metadata[:year].to_s.empty?

  sum = m.inject(0.0){|s,x| s += x[1]}

  d = m.inject(0.0){|s,x| s+= x[0]*x[1]} / sum
  #p [td, ad, yd]
  #p d

  d
end

#to_htmlObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/math_metadata_lookup/article.rb', line 111

def to_html
  result = %~
<div class="article">
    Id: <span class="id">#{::CGI.escapeHTML @metadata[:id].to_s}</span><br />
    Publication: <span class="publication">#{::CGI.escapeHTML @metadata[:publication].to_s}</span><br />
    Title: <span class="title">#{::CGI.escapeHTML @metadata[:title].to_s}</span><br />
    Authors: <span class="authors">#{::CGI.escapeHTML @metadata[:authors].to_a.join("; ")}</span><br />
    Year: <span class="year">#{::CGI.escapeHTML @metadata[:year].to_s}</span><br />
    Language: <span class="lang">#{::CGI.escapeHTML @metadata[:language].to_s}</span><br />
    MSC: <span class="msc">#{::CGI.escapeHTML @metadata[:msc].to_a.join("; ")}</span><br />
    Pages: <span class="pages">#{::CGI.escapeHTML @metadata[:range].to_s}</span><br />
    ISSN: <span class="issn">#{::CGI.escapeHTML @metadata[:issn].to_a.join('; ')}</span><br />
    Keywords: <span class="keywords">#{::CGI.escapeHTML @metadata[:keywords].to_a.join('; ')}</span><br />
    <a href="javascript:toggle_references('ref#{@metadata[:id]}')">References >>></a>
    <div id="ref#{@metadata[:id]}" name="ref#{@metadata[:id]}"class="references">
~
  @metadata[:references].to_a.each_with_index do |reference, idx|
    ref = reference.article
    result += %~
        <div class="reference">
            Source: #{::CGI.escapeHTML reference.source.to_s}
            Authors: #{::CGI.escapeHTML [ref[:authors]].flatten.join("; ")}
            Title: #{::CGI.escapeHTML ref[:title].to_s}
            Publication: #{::CGI.escapeHTML ref[:publication].to_s}
            Publisher: #{::CGI.escapeHTML ref[:publisher].to_s}
            Year: #{::CGI.escapeHTML ref[:year].to_s}
            Id: #{::CGI.escapeHTML ref[:id].to_s}
        </div>
~
  end
  result += %~
    </div>
</div>
~
  result
end

#to_textObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/math_metadata_lookup/article.rb', line 30

def to_text
  result = ""
  result += %~Id: #{@metadata[:id]}
Similarity: #{@metadata[:similarity]}
Publication: #{@metadata[:publication]}
Title: #{@metadata[:title]}
Authors: #{[@metadata[:authors]].flatten.join("; ")}
Year: #{@metadata[:year]}
Language: #{@metadata[:language]}
MSC: #{[@metadata[:msc]].flatten.join("; ")}
Pages: #{@metadata[:range]}
ISSN: #{@metadata[:issn].join('; ')}
Keywords: #{@metadata[:keywords].join('; ')}~
  @metadata[:references].to_a.each_with_index do |ref, idx|
    a = ref.article
    result += %~
Ref.: #{idx+1}. #{[a[:authors]].flatten.join("; ")}: #{a[:title]}~
  end
  result += "\n\n"
  result
end

#to_xmlObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/math_metadata_lookup/article.rb', line 53

def to_xml
  result = %~
    <article id="#{::CGI.escapeHTML @metadata[:id].to_s}" year="#{::CGI.escapeHTML @metadata[:year].to_s}" lang="#{::CGI.escapeHTML @metadata[:language].to_s}">
        <publication>#{::CGI.escapeHTML @metadata[:publication].to_s}</publication>
        <title>#{::CGI.escapeHTML @metadata[:title].to_s}</title>
        <authors>~
  @metadata[:authors].to_a.each do |author|
    result += %~
            <author>#{::CGI.escapeHTML author.to_s}</author>~
  end
  result += %~
        </authors>
        <msc>~
  @metadata[:msc].to_a.each do |msc|
    result += %~
            <class>#{::CGI.escapeHTML msc.to_s}</class>~
  end
  result += %~
        </msc>
        <pages>#{::CGI.escapeHTML @metadata[:range].to_s}</pages>~
    @metadata[:issn].to_a.each do |issn|
      result += %~
        <issn>#{::CGI.escapeHTML issn.to_s}</issn>~
    end
    @metadata[:keywords].to_a.each do |keyword|
      result += %~
        <keyword>#{::CGI.escapeHTML keyword.to_s}</keyword>~
    end
    result += %~
        <references>
~
  @metadata[:references].to_a.each_with_index do |reference, idx|
    ref = reference.article
    result += %~
            <reference id="#{::CGI.escapeHTML ref[:id].to_s}" number="#{::CGI.escapeHTML(ref[:number].to_s || (idx+1).to_s)}">
                <source>#{::CGI.escapeHTML reference.source.to_s}</source>
                <authors>~
    [ref[:authors]].flatten.each do |author|
      result += %~
                    <author>#{::CGI.escapeHTML author.to_s}</author>~
    end
    result += %~
                </authors>
                <title>#{::CGI.escapeHTML ref[:title].to_s}</title>
                <publication>#{::CGI.escapeHTML ref[:publication].to_s}</publication>
                <publisher>#{::CGI.escapeHTML ref[:publisher].to_s}</publisher>
                <year>#{::CGI.escapeHTML ref[:year].to_s}</year>
            </reference>
~
  end
  result += %~
        </references>
    </article>
~
  result
end