Add tentative export to RDF

This commit is contained in:
Théophile Bastian 2018-02-25 13:34:44 +01:00
parent 2732e4115f
commit c3bcdea1eb
2 changed files with 53 additions and 21 deletions

View 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)

View file

@ -4,8 +4,12 @@ import rdfserializer as rdf
from rdfserializer import RDFModelSerialiser as RDFModelSerializer from rdfserializer import RDFModelSerialiser as RDFModelSerializer
# ^ This was hurting my eyes way too much # ^ This was hurting my eyes way too much
from rdfserializer import SCHEMA as schema from rdfserializer import SCHEMA as schema
from rdflib.namespace import Namespace
import models as profile_models import profiles.models as profile_models
LOCAL_NS = Namespace('local:')
class RdfWebpage(RDFModelSerializer): class RdfWebpage(RDFModelSerializer):
@ -64,20 +68,20 @@ class RdfBrowserFingerprint(RDFModelSerializer):
model = profile_models.BrowserFingerprint model = profile_models.BrowserFingerprint
entries = [ entries = [
rdf.RDFSimpleField(schema.description, 'description'), rdf.RDFSimpleField(schema.description, 'description'),
rdf.RDFSimpleField('useragent', 'useragent'), rdf.RDFSimpleField(LOCAL_NS.useragent, 'useragent'),
rdf.RDFSimpleField('appname', 'appname'), rdf.RDFSimpleField(LOCAL_NS.appname, 'appname'),
rdf.RDFSimpleField('appversion', 'appversion'), rdf.RDFSimpleField(LOCAL_NS.appversion, 'appversion'),
rdf.RDFSimpleField('platform', 'platform'), rdf.RDFSimpleField(LOCAL_NS.platform, 'platform'),
rdf.RDFSimpleField('vendor', 'vendor'), rdf.RDFSimpleField(LOCAL_NS.vendor, 'vendor'),
rdf.RDFSimpleField('vendorsub', 'vendorsub'), rdf.RDFSimpleField(LOCAL_NS.vendorsub, 'vendorsub'),
rdf.RDFSimpleField('buildID', 'buildID'), rdf.RDFSimpleField(LOCAL_NS.buildID, 'buildID'),
rdf.RDFSimpleField('oscpu', 'oscpu'), rdf.RDFSimpleField(LOCAL_NS.oscpu, 'oscpu'),
rdf.RDFSimpleField('accept_encoding', 'accept_encoding'), rdf.RDFSimpleField(LOCAL_NS.accept_encoding, 'accept_encoding'),
rdf.RDFSimpleField('accept_default', 'accept_default'), rdf.RDFSimpleField(LOCAL_NS.accept_default, 'accept_default'),
rdf.RDFSimpleField('accept_lang', 'accept_lang'), rdf.RDFSimpleField(LOCAL_NS.accept_lang, 'accept_lang'),
rdf.RDFSimpleField('pixeldepth', 'pixeldepth'), rdf.RDFSimpleField(LOCAL_NS.pixeldepth, 'pixeldepth'),
rdf.RDFSimpleField('colordepth', 'colordepth'), rdf.RDFSimpleField(LOCAL_NS.colordepth, 'colordepth'),
rdf.RDFSimpleField('screens', 'screens'), rdf.RDFSimpleField(LOCAL_NS.screens, 'screens'),
] ]
@ -89,7 +93,7 @@ class RdfSearchEngine(RDFModelSerializer):
entries = [ entries = [
rdf.RDFSimpleField(schema.url, 'url'), rdf.RDFSimpleField(schema.url, 'url'),
rdf.RDFSimpleField(schema.name, 'name'), rdf.RDFSimpleField(schema.name, 'name'),
rdf.RDFSimpleField('query_pattern', 'query_pattern'), rdf.RDFSimpleField(LOCAL_NS.query_pattern, 'query_pattern'),
] ]
@ -114,13 +118,14 @@ class RdfProfile(RDFModelSerializer):
_type = schema.Person _type = schema.Person
model = profile_models.Profile model = profile_models.Profile
entries = [ entries = [
rdf.RDFSimpleField('nickname', 'nick'), rdf.RDFSimpleField(LOCAL_NS.nickname, 'nick'),
rdf.RDFSimpleField(schema.given_name, 'first_name'), rdf.RDFSimpleField(schema.given_name, 'first_name'),
rdf.RDFSimpleField(schema.family_name, 'last_name'), rdf.RDFSimpleField(schema.family_name, 'last_name'),
rdf.RDFSimpleField(schema.email, 'email'), rdf.RDFSimpleField(schema.email, 'email'),
rdf.RDFSimpleField('uses_urls', 'uses_urls'), rdf.RDFSimpleField(LOCAL_NS.uses_urls, 'uses_urls'),
rdf.RDFManyLinker('interest', 'interests', RdfInterest), rdf.RDFManyLinker(LOCAL_NS.interest, 'interests', RdfInterest),
rdf.RDFLeftBinder('search_engine', 'search_engine', RdfSearchEngine), rdf.RDFLeftBinder(LOCAL_NS.search_engine, 'search_engine',
rdf.RDFLeftBinder('browser_fingerprint', 'browser_fingerprint', RdfSearchEngine),
rdf.RDFLeftBinder(LOCAL_NS.browser_fingerprint, 'browser_fingerprint',
RdfBrowserFingerprint) RdfBrowserFingerprint)
] ]