<commit_before>package de.unibonn.iai.eis.diachron.qualitymetrics.intrinsic.accuracy;

import java.util.List;

import org.apache.log4j.Logger;

import com.hp.hpl.jena.datatypes.RDFDatatype;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.sparql.core.Quad;

import de.unibonn.iai.eis.diachron.qualitymetrics.DimensionNamesOntology;
import de.unibonn.iai.eis.diachron.qualitymetrics.QualityMetric;

/**
 * @author <NAME>
 * @date 13th Feb 2014
 */
public class MalformedDatatypeLiterals implements QualityMetric {

	static Logger logger = Logger.getLogger(MalformedDatatypeLiterals.class);

	private double totalLiterals = 0;
	private double malformedLiterals = 0;

	public double getTotalLiterals() {
		return totalLiterals;
	}

	public double getMalformedLiterals() {
		return malformedLiterals;
	}

	public void compute(Quad quad) {
		logger.trace("compute() --Started--");
		// retrieves object from statement
		Node object = quad.getObject();
		// checks if object is a literal
		if (object.isLiteral()) {
			// retrieves rdfDataType from literal
			RDFDatatype rdfdataType = object.getLiteralDatatype();
			// check if rdf data type is a valid data type
			if (null != rdfdataType) {
				logger.debug("RdfDataTypeLiteral :: " + object.toString());
				if (!rdfdataType.isValidLiteral(object.getLiteral())) {
					this.malformedLiterals++;
					logger.debug("MalformedRDFDataTypeLiteral :: "
							+ object.toString());
				}
				this.totalLiterals++;
			}
			logger.debug("Literal :: " + object.toString());

		}
		logger.debug("Object :: " + object.toString());
		logger.trace("compute() --Ended--");
	}

	public String getName() {
		return "MalformedDatatypeLiterals";
	}

	public double metricValue() {

		logger.trace("metricValue() --Started--");
		logger.debug("Malformed Literals :: " + this.malformedLiterals);
		logger.debug("Total Literals :: " + this.totalLiterals);

		// return ZERO if total number of RDF literals are ZERO [WARN]
		if (0 >= this.totalLiterals) {
			logger.warn("Total number of RDF data type literals in given document is found to be zero.");
			return 0.0;
		}

		double metricValue = this.malformedLiterals / this.totalLiterals;
		logger.debug("Metric Value :: " + metricValue);
		logger.trace("metricValue() --Ended--");
		return metricValue;
	}

	public List<Triple> toDAQTriples() {
		// TODO Auto-generated method stub
		return null;
	}

	public String getDimension() {
		return DimensionNamesOntology.INTRINSIC.ACCURACY;
	}

	public String getGroup() {
		return DimensionNamesOntology.INTRINSIC.GROUP_NAME;
	}

	public String getDescription() {
		// TODO Auto-generated method stub
		return null;
	}

}
<commit_msg>removed initalisation and added DAQ uris<commit_after>package de.unibonn.iai.eis.diachron.qualitymetrics.intrinsic.accuracy;

import java.util.List;

import org.apache.log4j.Logger;

import com.hp.hpl.jena.datatypes.RDFDatatype;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.sparql.core.Quad;

import de.unibonn.iai.eis.diachron.qualitymetrics.DimensionNamesOntology;
import de.unibonn.iai.eis.diachron.qualitymetrics.QualityMetric;
import de.unibonn.iai.eis.diachron.vocabularies.DAQ;

/**
 * @author <NAME>
 * @date 13th Feb 2014
 */
public class MalformedDatatypeLiterals implements QualityMetric {

	private final Resource CATEGORY_URI = DAQ.Intrinsic;
	private final Resource DIMENSION_URI = DAQ.Accuracy;
	private final Resource METRIC_URI = DAQ.MalformedDatatypeLiteralsMetric;
	
	private static Logger logger = Logger.getLogger(MalformedDatatypeLiterals.class);

	private double totalLiterals = 0;
	private double malformedLiterals = 0;

	public double getTotalLiterals() {
		return totalLiterals;
	}

	public double getMalformedLiterals() {
		return malformedLiterals;
	}

	public void compute(Quad quad) {
		logger.trace("compute() --Started--");
		// retrieves object from statement
		Node object = quad.getObject();
		// checks if object is a literal
		if (object.isLiteral()) {
			// retrieves rdfDataType from literal
			RDFDatatype rdfdataType = object.getLiteralDatatype();
			// check if rdf data type is a valid data type
			if (null != rdfdataType) {
				logger.debug("RdfDataTypeLiteral :: " + object.toString());
				if (!rdfdataType.isValidLiteral(object.getLiteral())) {
					this.malformedLiterals++;
					logger.debug("MalformedRDFDataTypeLiteral :: " + object.toString());
				}
				this.totalLiterals++;
			}
			logger.debug("Literal :: " + object.toString());

		}
		logger.debug("Object :: " + object.toString());
		logger.trace("compute() --Ended--");
	}

	public double metricValue() {

		logger.trace("metricValue() --Started--");
		logger.debug("Malformed Literals :: " + this.malformedLiterals);
		logger.debug("Total Literals :: " + this.totalLiterals);

		// return ZERO if total number of RDF literals are ZERO [WARN]
		if (0 >= this.totalLiterals) {
			logger.warn("Total number of RDF data type literals in given document is found to be zero.");
			return 0.0;
		}

		double metricValue = this.malformedLiterals / this.totalLiterals;
		logger.debug("Metric Value :: " + metricValue);
		logger.trace("metricValue() --Ended--");
		return metricValue;
	}

	public List<Triple> toDAQTriples() {
		// TODO Auto-generated method stub
		return null;
	}

	public Resource getMetricURI() {
		return this.METRIC_URI;
	}
	
	
	public Resource getDimensionURI() {
		return this.DIMENSION_URI;
	}

	public Resource getCategoryURI() {
		return this.CATEGORY_URI;
	}
}

{'fraction_non_alphanumeric': 0.11888716087782962, 'fraction_numerical': 0.00414722654224987, 'mean_word_length': 3.5042801556420233, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4159939', 'n_tokens_mistral': 2098, 'n_tokens_neox': 1848, 'n_words': 400}