Skip to content

Commit

Permalink
update graph count script to generate file in the reports folder
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jan 11, 2025
1 parent 2481b26 commit b7c6d34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
9 changes: 5 additions & 4 deletions bin/ncbo_generate_graph_count
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ require_relative '../lib/ncbo_cron'
config_exists = File.exist?(File.expand_path('../../config/config.rb', __FILE__))
abort("Please create a config/config.rb file using the config/config.rb.sample as a template") unless config_exists
require_relative '../config/config'
require_relative '../lib/ncbo_cron/graphs_counts'

require 'optparse'
options = {}
opt_parser = OptionParser.new do |opts|
opts.on('--store FILEPATH', 'save the results in this file') do |filepath|
options[:savefile] = filepath
end
options[:logfile] = "logs/graph_counts_generation.log"
options[:logfile] = STDOUT
opts.on( '-l', '--logfile FILE', "Write log to FILE (default is 'bulk_load_mapping.log')" ) do |filename|
options[:logfile] = filename
end
Expand All @@ -32,9 +33,9 @@ opt_parser.parse!
logger = Logger.new(options[:logfile])
puts "Processing details are logged to #{options[:logfile]}"
unless options[:savefile]
logger.error "Please provide a file to save the results"
logger.error "Please provide a file to save the results as an argument to --store FILEPATH"
exit
end

generator = NcboCron::GraphsCounts.new
generator.run(logger, options[:savefile])
NcboCron::GraphsCounts.run
NcboCron::GraphsCounts.run(logger, options[:savefile])
16 changes: 9 additions & 7 deletions lib/ncbo_cron/graphs_counts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
require 'optparse'

module NcboCron
module GraphsCounts
class GraphsCounts
SUBMISSION_DATA_GRAPH = 'http://data\.bioontology\.org/ontologies/[^/]+/submissions/\d+'
DATA_SAVE = 'reports/graph_counts.json'

def run(logger, file_path)
def run(logger, file_path = nil)
file_path ||= "#{LinkedData.settings.repository_folder}/#{DATA_SAVE}"
logger.info('Start generating graphs counts')
logger.info('Fetch ontologies data graphs')
@all_ontologies = LinkedData::Models::Ontology.all
@all_subs = all_ontologies.map{|x| x.latest_submission(status: any)}
@all_subs = @all_ontologies.map{|x| x.latest_submission(status: :any)}.compact

logger.info('Fetch all graphs URIs')
graphs = graphs_list
Expand All @@ -35,21 +37,21 @@ def save_result_in_file(file_path, results)

def zombie_graph?(graph)
regex = Regexp.new(SUBMISSION_DATA_GRAPH)
return false unless regex.match?(url)
return false unless regex.match?(graph)

!@all_subs.find{ |x| x.id.to_s == graph.to_s }.present?
end

def graph_count_triples(graph)
query = <<-eos
SELECT (COUNT(?s) as ?count) WHERE {
GRAPH #{graph.to_ntriples} {
GRAPH <#{graph}> {
?s ?p ?v
}}
eos
rs = Goo.sparql_query_client.query(query)
count = 0
rs.each do |sol|
rs.each_solution do |sol|
count = sol[:count].object
end
count
Expand All @@ -63,7 +65,7 @@ def graphs_list
}}
eos
rs = Goo.sparql_query_client.query(query)
rs.solutions.map { |x| x[:g].to_s }
rs.each_solution.map { |x| x[:g].to_s }
end
end
end

0 comments on commit b7c6d34

Please sign in to comment.