Merge rdf branch
This commit is contained in:
commit
517be1d822
4 changed files with 161 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -65,3 +65,4 @@ venv/
|
||||||
# Django stuff
|
# Django stuff
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
|
|
||||||
|
_vimrc_local.vim
|
||||||
|
|
27
profiles/management/commands/exportrdf.py
Normal file
27
profiles/management/commands/exportrdf.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from profiles.models_rdf import RdfProfile
|
||||||
|
from profiles import models
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
''' Exports database models to RDF '''
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
exported_models = [
|
||||||
|
models.Keyword,
|
||||||
|
models.Webpage,
|
||||||
|
models.Website,
|
||||||
|
models.Place,
|
||||||
|
models.Event,
|
||||||
|
models.BrowserFingerprint,
|
||||||
|
models.SearchEngine,
|
||||||
|
models.Interest,
|
||||||
|
models.Profile,
|
||||||
|
]
|
||||||
|
output_xml = RdfProfile().serialize(
|
||||||
|
# models=exported_models,
|
||||||
|
)
|
||||||
|
self.stdout.write(output_xml)
|
131
profiles/models_rdf.py
Normal file
131
profiles/models_rdf.py
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
""" RDF serialization class for profile models """
|
||||||
|
|
||||||
|
import rdfserializer as rdf
|
||||||
|
from rdfserializer import RDFModelSerialiser as RDFModelSerializer
|
||||||
|
# ^ This was hurting my eyes way too much
|
||||||
|
from rdfserializer import SCHEMA as schema
|
||||||
|
from rdflib.namespace import Namespace
|
||||||
|
|
||||||
|
import profiles.models as profile_models
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL_NS = Namespace('local:')
|
||||||
|
|
||||||
|
|
||||||
|
class RdfWebpage(RDFModelSerializer):
|
||||||
|
""" RDF serializer for Webpage """
|
||||||
|
|
||||||
|
_type = schema.WebPage
|
||||||
|
model = profile_models.Webpage
|
||||||
|
entries = [
|
||||||
|
rdf.RDFSimpleField(schema.url, 'url'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class RdfWebsite(RDFModelSerializer):
|
||||||
|
""" RDF serializer for Website """
|
||||||
|
|
||||||
|
_type = schema.WebSite
|
||||||
|
model = profile_models.Website
|
||||||
|
entries = [
|
||||||
|
rdf.RDFSimpleField(schema.name, 'name'),
|
||||||
|
rdf.RDFSimpleField(schema.url, 'url'),
|
||||||
|
rdf.RDFManyField(schema.keywords, 'keywords',
|
||||||
|
lambda keyword: keyword.text),
|
||||||
|
rdf.RDFManyLinker(schema.hasPart, 'notable_pages', RdfWebpage),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class RdfPlace(RDFModelSerializer):
|
||||||
|
""" RDF serializer for Place """
|
||||||
|
|
||||||
|
_type = schema.Place
|
||||||
|
model = profile_models.Place
|
||||||
|
entries = [
|
||||||
|
rdf.RDFSimpleField(schema.name, 'name'),
|
||||||
|
rdf.RDFSimpleField(schema.address, 'address'),
|
||||||
|
rdf.RDFSimpleField(schema.latitude, 'lat'),
|
||||||
|
rdf.RDFSimpleField(schema.longitude, 'lon'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class RdfEvent(RDFModelSerializer):
|
||||||
|
""" RDF serializer for Event """
|
||||||
|
|
||||||
|
_type = schema.Event
|
||||||
|
model = profile_models.Event
|
||||||
|
entries = [
|
||||||
|
rdf.RDFSimpleField(schema.name, 'name'),
|
||||||
|
rdf.RDFSimpleField(schema.startDate, 'date'),
|
||||||
|
rdf.RDFLeftBinder(schema.location, 'place', RdfPlace),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class RdfBrowserFingerprint(RDFModelSerializer):
|
||||||
|
""" RDF serializer for BrowserFingerprint """
|
||||||
|
|
||||||
|
_type = schema.Intangible
|
||||||
|
model = profile_models.BrowserFingerprint
|
||||||
|
entries = [
|
||||||
|
rdf.RDFSimpleField(schema.description, 'description'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.useragent, 'useragent'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.appname, 'appname'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.appversion, 'appversion'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.platform, 'platform'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.vendor, 'vendor'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.vendorsub, 'vendorsub'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.buildID, 'buildID'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.oscpu, 'oscpu'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.accept_encoding, 'accept_encoding'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.accept_default, 'accept_default'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.accept_lang, 'accept_lang'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.pixeldepth, 'pixeldepth'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.colordepth, 'colordepth'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.screens, 'screens'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class RdfSearchEngine(RDFModelSerializer):
|
||||||
|
""" RDF serializer for SearchEngine """
|
||||||
|
|
||||||
|
_type = schema.WebSite
|
||||||
|
model = profile_models.SearchEngine
|
||||||
|
entries = [
|
||||||
|
rdf.RDFSimpleField(schema.url, 'url'),
|
||||||
|
rdf.RDFSimpleField(schema.name, 'name'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.query_pattern, 'query_pattern'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class RdfInterest(RDFModelSerializer):
|
||||||
|
""" RDF serializer for Interest """
|
||||||
|
|
||||||
|
Interesttype = 'interest'
|
||||||
|
model = profile_models.Interest
|
||||||
|
entries = [
|
||||||
|
rdf.RDFSimpleField(schema.name, 'name'),
|
||||||
|
rdf.RDFManyField(schema.keywords, 'keywords',
|
||||||
|
lambda keyword: keyword.text),
|
||||||
|
rdf.RDFManyLinker(schema.location, 'places', RdfPlace),
|
||||||
|
rdf.RDFManyLinker(schema.website, 'websites', RdfWebsite),
|
||||||
|
rdf.RDFManyLinker(schema.event, 'events', RdfEvent),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class RdfProfile(RDFModelSerializer):
|
||||||
|
""" RDF serializer for Profile """
|
||||||
|
|
||||||
|
_type = schema.Person
|
||||||
|
model = profile_models.Profile
|
||||||
|
entries = [
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.nickname, 'nick'),
|
||||||
|
rdf.RDFSimpleField(schema.given_name, 'first_name'),
|
||||||
|
rdf.RDFSimpleField(schema.family_name, 'last_name'),
|
||||||
|
rdf.RDFSimpleField(schema.email, 'email'),
|
||||||
|
rdf.RDFSimpleField(LOCAL_NS.uses_urls, 'uses_urls'),
|
||||||
|
rdf.RDFManyLinker(LOCAL_NS.interest, 'interests', RdfInterest),
|
||||||
|
rdf.RDFLeftBinder(LOCAL_NS.search_engine, 'search_engine',
|
||||||
|
RdfSearchEngine),
|
||||||
|
rdf.RDFLeftBinder(LOCAL_NS.browser_fingerprint, 'browser_fingerprint',
|
||||||
|
RdfBrowserFingerprint)
|
||||||
|
]
|
|
@ -14,3 +14,5 @@ yarl==1.1.1
|
||||||
beautifulsoup4==4.6.0
|
beautifulsoup4==4.6.0
|
||||||
stem==1.6.0
|
stem==1.6.0
|
||||||
pycurl==7.43.0.1
|
pycurl==7.43.0.1
|
||||||
|
rdflib==4.2.2
|
||||||
|
git+https://github.com/tobast/RDFSerializer.git
|
||||||
|
|
Loading…
Reference in a new issue