<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package no.deichman.ls.adapter;

import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryException;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import java.util.HashMap;
import java.io.*;

import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.lang.LangRDFXML;

import com.hp.hpl.jena.rdf.model.*;

import no.deichman.ls.domain.Work;

/**
 *
 * @author rtg
 */
public class DataDeichmanAdapterDefault implements DataDeichmanAdapter {

    private final String dataDeichmanURL = "http://data.deichman.no/resource/tnr_"; // eg http://data.deichman.no/resource/tnr_749919
    private Model model = ModelFactory.createDefaultModel();
    private String url = null;

    private String endpointURI = "http://data.deichman.no/sparql";
    private final String getAllWorks = "prefix fabio: <http://purl.org/spar/fabio/> CONSTRUCT {?uri a fabio:Work } WHERE {?uri a fabio:Work }";

    private void dereference(String url) throws FileNotFoundException {

        RDFDataMgr.read(this.model, url, Lang.RDFXML);
    }

    private void setURL(String id) {

//    	TODO: Fix this nonsense
        //corny, eh? :-/
//    	this.url = this.dataDeichmanURL + id;
        this.url = "http://data.deichman.no/sparql?default-graph-uri=&query=describe+%3Chttp%3A%2F%2Fdata.deichman.no%2Fresource%2Ftnr_" + id + "%3E%0D%0A&format=application%2Frdf%2Bxml&timeout=0&debug=on";
    }

    @Override
    public Model getWorkList() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Model getWork(String id) throws FileNotFoundException {
        setURL(id);
        dereference(this.url);

        return this.model;<commit_msg>Modify SPARQL query to add Work details<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package no.deichman.ls.adapter;

import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryException;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import java.util.HashMap;
import java.io.*;

import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.lang.LangRDFXML;

import com.hp.hpl.jena.rdf.model.*;

import no.deichman.ls.domain.Work;

/**
 *
 * @author rtg
 */
public class DataDeichmanAdapterDefault implements DataDeichmanAdapter {

    private final String dataDeichmanURL = "http://data.deichman.no/resource/tnr_"; // eg http://data.deichman.no/resource/tnr_749919
    private Model model = ModelFactory.createDefaultModel();
    private String url = null;

    private String endpointURI = "http://data.deichman.no/sparql";
    private final String getAllWorks = "prefix fabio: <http://purl.org/spar/fabio/> prefix dcterms: <http://purl.org/dc/terms/> prefix foaf: <http://xmlns.com/foaf/0.1/> CONSTRUCT {?uri a fabio:Work; dcterms:creator ?author ; dcterms:title ?title ; fabio:hasManifestation ?manifestation } WHERE { ?uri a fabio:Work ; dcterms:creator ?creator ; dcterms:title ?title ; fabio:hasManifestation ?manifestation . ?creator foaf:name ?author }";

    private void dereference(String url) throws FileNotFoundException {

        RDFDataMgr.read(this.model, url, Lang.RDFXML);
    }

    private void setURL(String id) {

//    	TODO: Fix this nonsense
        //corny, eh? :-/
//    	this.url = this.dataDeichmanURL + id;
        this.url = "http://data.deichman.no/sparql?default-graph-uri=&query=describe+%3Chttp%3A%2F%2Fdata.deichman.no%2Fresource%2Ftnr_" + id + "%3E%0D%0A&format=application%2Frdf%2Bxml&timeout=0&debug=on";
    }

    @Override
    public Model getWorkList() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Model getWork(String id) throws FileNotFoundException {
        setURL(id);
        dereference(this.url);

        return this.model;
{'fraction_non_alphanumeric': 0.12476937269372694, 'fraction_numerical': 0.008763837638376383, 'mean_word_length': 3.6886486486486487, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7488367', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1466, 'n_words': 308}