<commit_before>require 'objspace'

class Neo4jRepository < Repository

  attr_accessor :neo

  def self.model_name
    return Repository.model_name
  end

  def self.default_port
    7474
  end

  # queries the graph in order to create an ontology that describes it...
  # 1. Get all nodes with certain labels and determine their properties + value types
  # 2. get all relations between different node types
  # 3. raise errors if we cannot reliably determine a "schema"  
  def create_ontology!
    properties = {}
    labels_and_counts.each_pair{|label, count| properties[label] = get_properties(label, count)}
    populate_ontology!(properties, get_relationships())
    return true
  end
    
  def get_relationships()
    return query_result("MATCH (a)-[r]->(b) RETURN labels(a)[0] AS This, type(r) as To, labels(b)[0] AS That, count(*) AS Count")
  end
  
  # yeah, sue me ... this is slow as f**k, but it does the job ^^
  def get_properties(label, count)
    offset = sensible_offset(label)
    rounds = (count / offset).to_i<commit_msg>Produce rdf documents for ontologies that describe Neo4j Graphs<commit_after>require 'objspace'

class Neo4jRepository < Repository

  attr_accessor :neo

  def self.model_name
    return Repository.model_name
  end
  
  def self.rdf_format
    "rdf"
  end

  def self.default_port
    7474
  end

  # queries the graph in order to create an ontology that describes it...
  # 1. Get all nodes with certain labels and determine their properties + value types
  # 2. get all relations between different node types
  # 3. raise errors if we cannot reliably determine a "schema"  
  def create_ontology!
    properties = {}
    labels_and_counts.each_pair{|label, count| properties[label] = get_properties(label, count)}
    populate_ontology!(properties, get_relationships())
    return true
  end
    
  def get_relationships()
    return query_result("MATCH (a)-[r]->(b) RETURN labels(a)[0] AS This, type(r) as To, labels(b)[0] AS That, count(*) AS Count")
  end
  
  # yeah, sue me ... this is slow as f**k, but it does the job ^^
  def get_properties(label, count)
    offset = sensible_offset(label)
    rounds = (count / offset).to_i
{'fraction_non_alphanumeric': 0.09032553874369555, 'fraction_numerical': 0.009628610729023384, 'mean_word_length': 3.613107822410148, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7238488', 'n_tokens_mistral': 698, 'n_tokens_neox': 665, 'n_words': 237}