Add tentative export to RDF
This commit is contained in:
parent
2732e4115f
commit
c3bcdea1eb
2 changed files with 53 additions and 21 deletions
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)
|
|
@ -4,8 +4,12 @@ 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 models as profile_models
|
||||
import profiles.models as profile_models
|
||||
|
||||
|
||||
LOCAL_NS = Namespace('local:')
|
||||
|
||||
|
||||
class RdfWebpage(RDFModelSerializer):
|
||||
|
@ -64,20 +68,20 @@ class RdfBrowserFingerprint(RDFModelSerializer):
|
|||
model = profile_models.BrowserFingerprint
|
||||
entries = [
|
||||
rdf.RDFSimpleField(schema.description, 'description'),
|
||||
rdf.RDFSimpleField('useragent', 'useragent'),
|
||||
rdf.RDFSimpleField('appname', 'appname'),
|
||||
rdf.RDFSimpleField('appversion', 'appversion'),
|
||||
rdf.RDFSimpleField('platform', 'platform'),
|
||||
rdf.RDFSimpleField('vendor', 'vendor'),
|
||||
rdf.RDFSimpleField('vendorsub', 'vendorsub'),
|
||||
rdf.RDFSimpleField('buildID', 'buildID'),
|
||||
rdf.RDFSimpleField('oscpu', 'oscpu'),
|
||||
rdf.RDFSimpleField('accept_encoding', 'accept_encoding'),
|
||||
rdf.RDFSimpleField('accept_default', 'accept_default'),
|
||||
rdf.RDFSimpleField('accept_lang', 'accept_lang'),
|
||||
rdf.RDFSimpleField('pixeldepth', 'pixeldepth'),
|
||||
rdf.RDFSimpleField('colordepth', 'colordepth'),
|
||||
rdf.RDFSimpleField('screens', 'screens'),
|
||||
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'),
|
||||
]
|
||||
|
||||
|
||||
|
@ -89,7 +93,7 @@ class RdfSearchEngine(RDFModelSerializer):
|
|||
entries = [
|
||||
rdf.RDFSimpleField(schema.url, 'url'),
|
||||
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
|
||||
model = profile_models.Profile
|
||||
entries = [
|
||||
rdf.RDFSimpleField('nickname', 'nick'),
|
||||
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('uses_urls', 'uses_urls'),
|
||||
rdf.RDFManyLinker('interest', 'interests', RdfInterest),
|
||||
rdf.RDFLeftBinder('search_engine', 'search_engine', RdfSearchEngine),
|
||||
rdf.RDFLeftBinder('browser_fingerprint', 'browser_fingerprint',
|
||||
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)
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue