Skip to content

Instantly share code, notes, and snippets.

View msalvadores's full-sized avatar

Manuel Salvadores msalvadores

View GitHub Profile
@msalvadores
msalvadores / dwcterms_owl.rdf
Created June 5, 2014 19:47
dwc_terms_owl.rdf
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY dcam "http://purl.org/dc/dcam/" >
<!ENTITY dcterms "http://purl.org/dc/terms/" >
<!ENTITY dcmitype "http://purl.org/dc/dcmitype/" >
<!ENTITY dwc "http://rs.tdwg.org/dwc/terms/" >
<!ENTITY dwctype "http://rs.tdwg.org/dwc/dwctype/" >
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
@msalvadores
msalvadores / traverse_go_classes.py
Last active August 29, 2015 14:07
A simple script to traverse all GO classes
import requests
import time
import pdb
import json
import sys
import urllib
FILE_NAME = "ontology_ids_and_parents.txt"
APIKEY = 'YOUR KEY'
@msalvadores
msalvadores / gist:851417
Created March 2, 2011 18:25
code to get all var names hanging from a rasqal_expression
/*
code to get all var names hanging from a rasqal_expression
author: Manuel Salvadores (msalvadores@gmail.com)
*/
static void get_var_names(rasqal_expression *e,GList **list_vars) {
GList *l = *list_vars;
if (!e) return;
if (e->literal != NULL) {
rasqal_literal *lit = e->literal;
@msalvadores
msalvadores / gist:925093
Created April 18, 2011 09:57
Data example for 4sr tutorial
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix def: <http://foo.com/def/> .
@prefix id: <http://foo.com/id/> .
############################################################
##### RDFS SCHEMA
############################################################
######## rdfs:subClassOf hierarchy
@msalvadores
msalvadores / gist:1006138
Created June 3, 2011 10:18
python-find-occurrences-of-strings-from-a-reference-file-within-an-input-file
#stackoverflow answer http://stackoverflow.com/questions/6225590/python-find-occurrences-of-strings-from-a-reference-file-within-an-input-file
def count_line_occurrences(ref_list,input_list):
line_counter = {}
# Initialization
for ref_line in ref_list:
ref_line = ref_line.rstrip()
line_counter[ref_line] = 0
for input_line in input_list:
input_line = input_line.rstrip()
@msalvadores
msalvadores / gist:1212562
Created September 12, 2011 21:47
Java class to export Protege 3 database backend.
package ncbo.proto;
import java.io.FileInputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
import edu.stanford.smi.protegex.owl.database.creator.OwlDatabaseCreator;
import edu.stanford.smi.protegex.owl.model.OWLModel;
@msalvadores
msalvadores / gist:1251188
Created September 29, 2011 16:34
Bioportal Mapping Example (Turtle Syntax)
#Ontology here http://protege.stanford.edu/ontologies/mappings/mappings.rdfs
<http://purl.bioontology.org/mapping/21d7a8e0-004d-012e-74a1-005056bd0010>
<http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#created_in_source_ontology_version> 40400 ;
<http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#created_in_target_ontology_version> 42693 ;
<http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#date> "2010-05-17T23:24:34Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> ;
<http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#mapping_source> "Application" ;
<http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#mapping_source_algorithm> "Mappings were generated by the LOOM algorithm automatically based on close lexical match between preferred names of terms or a preferred name and a synonym." ;
<http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#mapping_source_contact_info> "support@bioontology.org" ;
<http://protege.stanford.
@msalvadores
msalvadores / test_sparql_bioportal.py
Created October 5, 2011 01:53
BioPortal SPARQL Sample Script (Python)
import json
import urllib2
import urllib
import traceback
import sys
def query(q,apikey,epr,f='application/json'):
"""Function that uses urllib/urllib2 to issue a SPARQL query.
By default it requests json as data format for the SPARQL resultset"""
@msalvadores
msalvadores / gist:1473419
Created December 13, 2011 19:12
fast filtered output test
package test;
import java.io.PrintStream;
public class TestOutput {
public static void outputFiltered(String label, PrintStream out) {
for (byte b : label.getBytes()) {
if (Character.isLetterOrDigit((char)b)) {
out.print((char)b);
@msalvadores
msalvadores / gist:2210491
Created March 26, 2012 23:12
Simple Python Script to Query sparql.bioportal.org
import json,urllib2,urllib,traceback, sys
def query(q,apikey,epr,f='application/json'):
try:
params = {'query': q, 'apikey': apikey}
params = urllib.urlencode(params)
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request(epr+'?'+params)
request.add_header('Accept', f)
request.get_method = lambda: 'GET'