# -*- coding: UTF-8 -*- """Module for traversing the ETL graph""" # Copyright 2005, 2006 EIAO Consoritum # This program is distributed under the terms of the GNU General # Public License. # # This file is part of the European Internet Accessibility Observatory # (EIAO) # # EIAO is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # EIAO is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with EIAO; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301 USA __author__ = 'Morten Goodwin Olsen, Jens Frøkjær, Tom Oddershede' __maintainer__ = 'Nils Ulltveit-Moe' __version__ = "$Id$" eiao = "http://www.eiao.net/rdf/2.0#" eiaostat = "http://www.eiao.net/rdf/" purl10 = "http://purl.org/dc/elements/1.0/" purl11 = "http://purl.org/dc/elements/1.1/" wai = "http://www.w3.org/WAI/ER/EARL/nmg-strawman#" def getResultsFromPageScenario(rdfreader, pagesurvey): """Retrieves results from a pagesurvey Keyword arguements: rdfreader -- Active RDFreaderwriter with an open connection to a RDF graph pagesurvey -- pagesurveyid as string Returns a list of tuples as [(result, barrierindicator,line,column), (result, barrierindicator,line,column)] """ returnresults = [] allassertions = [assertion for assertion in rdfreader(subject = pagesurvey, predicate = wai+'asserts',object=None,readonlyonce=True)] for assertion in allassertions: result = rdfreader(subject = assertion, predicate = wai+'result' ,object=None,readonlyonce=True)#[0]['object'] validity = rdfreader(subject = result, predicate = wai+'validity' ,object=None,readonlyonce=True)#[0]['object'] validity = validity[validity.rfind('#')+1:] barrierIndicator = rdfreader(subject = result, predicate = eiao+'barrierIndicator' ,object=None,readonlyonce=True) if barrierIndicator: barrierIndicator = float(barrierIndicator[0]['object']) else: barrierIndicator = None location = rdfreader(subject = assertion, predicate = eiao+'singleLocation' ,object=None,readonlyonce=True)#[0]['object'] line = int(rdfreader(subject = location, predicate = eiao+'line' ,object=None,readonlyonce=True))#[0]['object']) column = int(rdfreader(subject = location, predicate = eiao+'column' ,object=None,readonlyonce=True))#[0]['object']) returnresults.append((validity,barrierIndicator,line,column)) return returnresults def getMetaDataFromPageSurvey(rdfreader,pagesurvey,restriction=None): """Retrieves metadata from a pagesurvey Keyword arguments: rdfreader -- Active RDFreaderwriter with an open connection to a RDF graph pagesurvey -- pagesurveyid as string restriction -- [Optional] If only one type of meta data should be extracted e.g. technology, language, mediatype returns a list of tuples as [(type,value,line,column,page),(type,value,line,column,page)] """ returnmetadata = [] allmetadata = [metadata for metadata in rdfreader(subject = pagesurvey, predicate = eiao+'metadata',object=None,readonlyonce=True)] for metadata in allmetadata: type = rdfreader(subject = metadata, predicate = eiao+'type',object=None) type = type[type.rfind('#')+1:] if (not restriction) or restriction==type: value = rdfreader(subject = metadata, predicate = eiao+'value',object=None,readonlyonce=True) page = rdfreader(subject = metadata, predicate = wai+'subject',object=None,readonlyonce=True) singlelocation = rdfreader(subject = metadata, predicate = eiao+'singleLocation',object=None,readonlyonce=True) line = int(rdfreader(subject = singlelocation, predicate = eiao+'line',object=None,readonlyonce=True)) column = int(rdfreader(subject = singlelocation, predicate = eiao+'column',object=None,readonlyonce=True)) returnmetadata.append((type,value,line,column,page)) return returnmetadata def getScenarioData(rdfreader,scenario): """Retrieved data from a scenario Keyword arguments: rdfreader -- Active RDFreaderwriter with an open connection to a RDF graph scenario -- Scenario ID as string Returns a tuple of (typeofscenario,rangelocation,barrierindicator,pagesurvey) """ typeofscenario = rdfreader(subject = scenario, predicate = eiao+'typeofscenario',object=None,readonlyonce=True)#[0]['object'] rangelocation = rdfreader(subject = scenario, predicate = eiao+'rangeLocation',object=None,readonlyonce=True)#[0]['object'] barrierindicator = float(rdfreader(subject = scenario, predicate = eiao+'barrierIndicator',object=None,readonlyonce=True))#[0]['object']) pagesurvey = rdfreader(subject = scenario, predicate = eiao+'pageSurvey',object=None,readonlyonce=True)#[0]['object'] return (typeofscenario,rangelocation,barrierindicator,pagesurvey) def getSiteSurveyData(rdfreader, sitesurvey): """Rettrieved data from a SiteSurvey Keyword arguments: rdfreader -- Active RDFreaderwriter with an open connection to a RDF graph sitesurvey -- SiteSurvey ID as string Returns a tuple of (basedownloaddir,website,barrierindicator,variance,errormargin,urlcount) """ basedownloaddir = rdfreader(subject = sitesurvey, predicate = eiao+'basedownloaddir',object=None,readonlyonce=True)#[0]['object'] website = rdfreader(subject = sitesurvey, predicate = eiao+'webSite',object=None,readonlyonce=True)#[0]['object'] barrierindicator = float(rdfreader(subject = sitesurvey, predicate = eiao+'barrierIndicator',object=None,readonlyonce=True))#[0]['object']) variance = float(rdfreader(subject = sitesurvey, predicate = eiao+'variance',object=None,readonlyonce=True))#[0]['object']) errormargin = float(rdfreader(subject = sitesurvey, predicate = eiao+'errorMargin',object=None,readonlyonce=True))#[0]['object']) urlcount = int(rdfreader(subject = sitesurvey, predicate = eiao+'urlCount',object=None,readonlyonce=True))#[0]['object']) return (basedownloaddir,website,barrierindicator,variance,errormargin,urlcount) def getTestSubjectFromPageSurvey(rdfreader, pagesurvey): """Retrieves the TestSubject from a PageSurvey Keyword arguments: rdfreader -- Active RDFReaderwriter with an open connection to a RDF graph pagesurvey -- PageSurvey ID as string Returns TestSubjectID as String """ return rdfreader(subject = pagesurvey, predicate = wai+'testsubject',object=None,readonlyonce=True)#[0]['object'] def getDataFromTestSubject(rdfreader, testsubject): """Retrieved MetaData from a TestSubject Keyword arguments: rdfreader -- Active RDFreaderwriter with an open connection to a RDF graph testsubject -- ID of testsubject returns a tuple of (uncheckable, unavailable, contentlength, calculatedsize, title, date) """ uncheckable,unavailable,contentlength = 0,0,None #Optional values uncheckablet = rdfreader(subject = testsubject, predicate = eiao+'uncheckableCount',object=None,readonlyonce=True) if uncheckablet: uncheckable = int(uncheckablet)#[0]['object']) unavailablet = rdfreader(subject = testsubject, predicate = eiao+'unavailableCount',object=None,readonlyonce=True) if unavailablet: unavailable = int(unavailablet)#[0]['object']) contentlengtht = rdfreader(subject = testsubject, predicate = eiao+'contentLength',object=None,readonlyonce=True) if contentlengtht: contentlength = int(contentlengtht)#[0]['object']) calculatedsize = int(rdfreader(subject = testsubject, predicate = eiao+'calculatedSize',object=None,readonlyonce=True))#[0]['object']) title = rdfreader(subject = testsubject, predicate = purl11+'title',object=None,readonlyonce=True)#[0]['object'] date = rdfreader(subject = testsubject, predicate = purl11+'date',object=None,readonlyonce=True)#[0]['object'] return (uncheckable, unavailable, contentlength, calculatedsize, title, date)