Skip to content

Instantly share code, notes, and snippets.

View mommi84's full-sized avatar
🔮
AI-Driven Strategic Foresight

Tom Soru mommi84

🔮
AI-Driven Strategic Foresight
View GitHub Profile
@mommi84
mommi84 / nlp_dependency_tree.py
Created August 12, 2022 16:08
Visualise NLP dependency trees
#!/usr/bin/env python3
#
# Requirements:
# pip3 install spacy graphviz
# python3 -m spacy download en_core_web_lg
#
import spacy
from graphviz import Digraph
nlp = spacy.load('en_core_web_lg')
@mommi84
mommi84 / code-dbpedia-radial-dendogram.ipynb
Last active December 2, 2020 12:38
Code for DBpedia Ontology as a radial dendogram.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mommi84
mommi84 / predict_range.sparql
Last active July 30, 2020 18:45
Predict range of property among datatypes and high-level classes.
select ?x (count(*) as ?c) {
[] <PROPERTY_URI> ?o .
optional {
?o a/rdfs:subClassOf+ ?class .
?class rdfs:subClassOf owl:Thing
}
bind(if(
isuri(?o),
?class,
datatype(?o)
@mommi84
mommi84 / ntriples_to_tsv.sh
Last active July 10, 2020 22:11
NTriples to TSV without literals.
#!/usr/bin/env bash
ntriples=$1
tsv=$2
sed -n $'s/^<\([^ ]*\)> <\([^ ]*\)> <\([^ ]*\)> \.$/\\1\t\\2\t\\3/p' $ntriples > $tsv
@mommi84
mommi84 / differences.sparql
Last active July 6, 2020 15:06
Differences between entities in SPARQL
# list all differences between two entities, filtered by certain properties
SELECT * WHERE {
{
<http://dbpedia.org/resource/Nevada> ?p ?o1
MINUS { <http://dbpedia.org/resource/Lincoln_County,_Nevada> ?p ?o1 }
} UNION {
<http://dbpedia.org/resource/Lincoln_County,_Nevada> ?p ?o2
MINUS { <http://dbpedia.org/resource/Nevada> ?p ?o2 }
}
@mommi84
mommi84 / lod_count.sh
Created May 26, 2020 00:22
Count triples in the LOD cloud.
#!/bin/bash
curl -s https://lod-cloud.net/lod-data.json | jq '.[] | .triples' | sed -e $'s/"//g' | awk '{s+=$1} END {printf "%d\n", s}'
@mommi84
mommi84 / quickstart.sh
Last active June 5, 2020 11:25
New Python environment quickstart.
#!/usr/bin/env bash
python3 -m venv env
source env/bin/activate
pip3 install ipykernel jupyter
python3 -m ipykernel install --user --name=env
jupyter notebook
# for 'requirements.txt':
# pip3 freeze > requirements.txt
@mommi84
mommi84 / pysparql3.py
Created February 16, 2020 18:58
Generic simple SPARQL interface for Python v3.
#!/usr/bin/env python
import http, json, base64
from urllib.request import Request, urlopen
from urllib.parse import urlencode
from urllib.error import HTTPError
from time import time
class PySparql():
def __init__(this, endpoint, username=None, password=None, buffer_size=10000):
@mommi84
mommi84 / parse_ntriples.py
Created September 30, 2019 10:28
Parse NTriples Quickstart
#!/usr/bin/env python
from rdflib.plugins.parsers.ntriples import NTriplesParser, Sink
filename = 'input.nt'
class MySink(Sink):
def triple(self, s, p, o):
pass
sink = MySink()
@mommi84
mommi84 / add_swap.sh
Created September 12, 2019 09:33
Add swap memory on Ubuntu
#!/usr/bin/env bash
#
# USAGE:
# sudo ./add_swap.sh 4G
#
# SOURCE:
# https://linuxize.com/post/how-to-add-swap-space-on-ubuntu-18-04/
#
fallocate -l $1 /swapfile
chmod 600 /swapfile