Skip to content

Instantly share code, notes, and snippets.

Avatar
🖖

Tommaso Soru mommi84

🖖
View GitHub Profile
@mommi84
mommi84 / predict_range.sparql
Last active Jul 30, 2020
Predict range of property among datatypes and high-level classes.
View predict_range.sparql
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 Jul 10, 2020
NTriples to TSV without literals.
View ntriples_to_tsv.sh
#!/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 Jul 6, 2020
Differences between entities in SPARQL
View differences.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
Count triples in the LOD cloud.
View lod_count.sh
#!/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 Jun 5, 2020
New Python environment quickstart.
View quickstart.sh
#!/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 Feb 16, 2020
Generic simple SPARQL interface for Python v3.
View pysparql3.py
#!/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 Sep 30, 2019
Parse NTriples Quickstart
View parse_ntriples.py
#!/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 Sep 12, 2019
Add swap memory on Ubuntu
View add_swap.sh
#!/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
@mommi84
mommi84 / extend.sh
Created Sep 10, 2019
Extend Ubuntu SSD in AWS
View extend.sh
# After having extended the SSD size via AWS console:
ubuntu@ip-172-31-46-157:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop1 7:1 0 18M 1 loop /snap/amazon-ssm-agent/1455
loop2 7:2 0 88.7M 1 loop /snap/core/7396
loop3 7:3 0 89M 1 loop /snap/core/7713
xvda 202:0 0 100G 0 disk
└─xvda1 202:1 0 50G 0 part /
@mommi84
mommi84 / dbpedia_file_urls.sparql
Last active Jul 10, 2020
Get DBpedia file URLs by version and language.
View dbpedia_file_urls.sparql
#
# Endpoint: https://databus.dbpedia.org/repo/sparql
# Credits: @JJ-Author, @mommi84
#
PREFIX dataid: <http://dataid.dbpedia.org/ns/core#>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX dcv: <http://dataid.dbpedia.org/ns/cv#>
SELECT DISTINCT ?url WHERE {
You can’t perform that action at this time.