<commit_before>#!/usr/bin/env python3
from rdflib import Graph, URIRef
from pyontutils.neurons import *
from pyontutils.utils import makeGraph, makePrefixes

__all__ = [
    'AND',
    'OR',
    'graphBase',
    'Phenotype',
    'NegPhenotype',
    'LogicalPhenotype',
    'Neuron',
    'pred',
    'WRITE',
]

# quick way to do renaming during dev and testing
g = globals()
def rename(classname, newname):
    cls = g[classname]
    setattr(cls, '__name__', newname)
    g[newname] = cls

_ = [rename(old, new) for old, new in (
    ('DefinedNeuron','Neuron'),
    ('PhenotypeEdge','Phenotype'),
    ('NegPhenotypeEdge','NegPhenotype'),
    ('LogicalPhenoEdge','LogicalPhenotype'),
)]

core_graph_path = '/tmp/NIF-Phenotype-Core.ttl'
pheno_graph_path = '/tmp/NIF-Phenotypes.ttl'

in_graph_path = core_graph_path #/tmp/output.ttl'
out_graph_path =  '/tmp/_Neurons.ttl'

graphBase.core_graph = Graph()
graphBase.core_graph.parse(core_graph_path, format='turtle')
graphBase.core_graph.parse(pheno_graph_path, format='turtle')
graphBase.in_graph = graphBase.core_graph
graphBase.in_graph.parse(in_graph_path, format='turtle')
graphBase.in_graph.namespace_manager.bind('ILXREPLACE', makePrefixes('ILXREPLACE')['ILXREPLACE'])  # FIXME annoying
graphBase.in_graph.namespace_manager.bind('GO', makePrefixes('GO')['GO'])  # FIXME annoying
graphBase.in_graph.namespace_manager.bind('CHEBI', makePrefixes('CHEBI')['CHEBI'])  # FIXME annoying
graphBase.out_graph = Graph()
graphBase._predicates = getPhenotypePredicates(graphBase.core_graph)
pred = graphBase._predicates  # keep the predicates in their own namespace

newGraph = makeGraph('',
                     prefixes=makePrefixes('owl',
                                           'GO',
                                           'PR',
                                           'CHEBI',
                                           'UBERON',
                                           'NCBITaxon',
                                           'ILXREPLACE',
                                           'ilx',
                                           'ILX',
                                           'NIFCELL',
                                           'NIFMOL',),
                     graph=graphBase.out_graph)
newGraph.filename = out_graph_path
ontid = URIRef('file://' + out_graph_path)
newGraph.add_ont(ontid, 'Some Neurons')
newGraph.add_node(ontid, 'owl:imports', URIRef('file://' + pheno_graph_path))  # core should be in the import closure

tg = makeGraph('NONE', graph=graphBase.in_graph)
e = tg.get_equiv_inter(NIFCELL_NEURON)  # FIXME do this on demand
graphBase.existing_ids = e

def WRITE():
    newGraph.write()
<commit_msg>neuron lang updated to import files from the neurons branch on github<commit_after>#!/usr/bin/env python3
from rdflib import Graph, URIRef
from pyontutils.neurons import *
from pyontutils.utils import makeGraph, makePrefixes

__all__ = [
    'AND',
    'OR',
    'graphBase',
    'Phenotype',
    'NegPhenotype',
    'LogicalPhenotype',
    'Neuron',
    'pred',
    'WRITE',
]

# quick way to do renaming during dev and testing
g = globals()
def rename(classname, newname):
    cls = g[classname]
    setattr(cls, '__name__', newname)
    g[newname] = cls

_ = [rename(old, new) for old, new in (
    ('DefinedNeuron','Neuron'),
    ('PhenotypeEdge','Phenotype'),
    ('NegPhenotypeEdge','NegPhenotype'),
    ('LogicalPhenoEdge','LogicalPhenotype'),
)]

core_graph_path = 'https://raw.githubusercontent.com/SciCrunch/NIF-Ontology/neurons/ttl/NIF-Phenotype-Core.ttl'
pheno_graph_path = 'https://raw.githubusercontent.com/SciCrunch/NIF-Ontology/neurons/ttl/NIF-Phenotypes.ttl'

in_graph_path = core_graph_path #/tmp/output.ttl'
out_graph_path =  '/tmp/_Neurons.ttl'

graphBase.core_graph = Graph()
graphBase.core_graph.parse(core_graph_path, format='turtle')
graphBase.core_graph.parse(pheno_graph_path, format='turtle')
graphBase.in_graph = graphBase.core_graph
graphBase.in_graph.parse(in_graph_path, format='turtle')
graphBase.in_graph.namespace_manager.bind('ILXREPLACE', makePrefixes('ILXREPLACE')['ILXREPLACE'])  # FIXME annoying
graphBase.in_graph.namespace_manager.bind('GO', makePrefixes('GO')['GO'])  # FIXME annoying
graphBase.in_graph.namespace_manager.bind('CHEBI', makePrefixes('CHEBI')['CHEBI'])  # FIXME annoying
graphBase.out_graph = Graph()
graphBase._predicates = getPhenotypePredicates(graphBase.core_graph)
pred = graphBase._predicates  # keep the predicates in their own namespace

newGraph = makeGraph('',
                     prefixes=makePrefixes('owl',
                                           'GO',
                                           'PR',
                                           'CHEBI',
                                           'UBERON',
                                           'NCBITaxon',
                                           'ILXREPLACE',
                                           'ilx',
                                           'ILX',
                                           'NIFCELL',
                                           'NIFMOL',),
                     graph=graphBase.out_graph)
newGraph.filename = out_graph_path
ontid = URIRef('file://' + out_graph_path)
newGraph.add_ont(ontid, 'Some Neurons')
newGraph.add_node(ontid, 'owl:imports', URIRef(pheno_graph_path))  # core should be in the import closure

tg = makeGraph('NONE', graph=graphBase.in_graph)
e = tg.get_equiv_inter(NIFCELL_NEURON)  # FIXME do this on demand
graphBase.existing_ids = e

def WRITE():
    newGraph.write()

{'fraction_non_alphanumeric': 0.11962414166967836, 'fraction_numerical': 0.0003614022406938923, 'mean_word_length': 2.437888198757764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '782194', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1712, 'n_words': 306}