<commit_before>/**
 * @module libsbgn-annotations
 * @namespace libsbgn.annot
*/

var checkParams = require('./utilities').checkParams;
var $rdf = require('rdflib');
var xmldom = require('xmldom');
var N3 = require('n3');
var Util = require('./annotation-utils');

var ns = {};

/*
	EXAMPLE:

	<rdf:RDF 
		xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	    xmlns:bqmodel="http://biomodels.net/model-qualifiers/"
	    xmlns:bqbiol="http://biomodels.net/biology-qualifiers/"
	    xmlns:eisbm="http://www.eisbm.org/rdf-annotation-newt/">
		<rdf:Description rdf:about="#_000001">
			<bqmodel:is>
				<rdf:Bag>
					<rdf:li rdf:resource="http://identifiers.org/biomodels.db/BIOMD0000000004" />
				</rdf:Bag>
			</bqmodel:is>

			<bqmodel:isDescribedBy>
				<rdf:Bag>
					<rdf:li rdf:resource="http://identifiers.org/pubmed/1833774" />
				</rdf:Bag>
			</bqmodel:isDescribedBy>

			<eisbm:hasProperty>
				<rdf:Bag>
					<eisbm:item eisbm:key="data" eisbm:value="42" />
					<eisbm:item eisbm:key="data2" eisbm:value="1.23" />
				</rdf:Bag>
			</eisbm:hasProperty>

		</rdf:Description>
	</rdf:RDF> 


*/

//ns.xmlns = "http://www.sbml.org/sbml/level3/version1/render/version1";

// ------- ANNOTATION -------
/**
 * Represents the <code>&lt;annotation&gt;</code> element.
 * @class
 */
var Annotation = function (params) {
	var params = checkParams(params, ['rdfElement']);
	this.rdfElement = params.rdfElement;
};

/**
 * @param {RdfElement} rdfElement
 */
Annotation.prototype.setRdfElement = function(rdfElement) {
	this.rdfElement = rdfElement;
};

/**
 * @return {Element}
 */
Annotation.prototype.buildXmlObj = function () {
	var annotation = new xmldom.DOMImplementation().createDocument().createElement('annotation');
	if (this.rdfElement != null) {
		var rdf = this.rdfElement;
		// need to parse the string returned by serializing the rdf into a dom element
		var xmlDoc = new xmldom.DOMParser().parseFromString(rdf.toXML(), "text/xml");
		var rdfDOMElement = xmlDoc.getElementsByTagName('rdf:RDF')[0];
		annotation.appendChild(rdfDOMElement);
	}
	return annotation;
};

/**
 * @return {string}
 */
Annotation.prototype.toXML = function() {
	return new xmldom.XMLSerializer().serializeToString(this.buildXmlObj());
};

/**
 * @param {Element} xml
 * @return {Annotation}
 */
Annotation.fromXML = function (xml) {
	if (xml.tagName != 'annotation') {
		throw new Error("Bad XML provided, expected tagName annotation, got: " + xml.tagName);
	}
	var annotation = new ns.Annotation();


	var rdfXML = xml.getElementsByTagName('rdf:RDF')[0];
	if (rdfXML != null) {
		var rdf = ns.RdfElement.fromXML(rdfXML);
		annotation.setRdfElement(rdf);
	}

	return annotation;
};
ns.Annotation = Annotation;
// ------- END ANNOTATION -------

// ------- GLOBALSTORE -------
var GlobalRdfStore = function () {
	this.store = N3.Store();
};

GlobalRdfStore.prototype.load = function (annotations) {
	for(var i=0; i<annotations.length; i++) {
		var annot = annotations[i];
		if(annot.rdfElement != null) {
			var rdfElement = annot.rdfElements;
			this.store.addTriples(rdfElement.store.getTriples());
		}
	}
	this.store.addPrefixes(Util.prefixes);
};

GlobalRdfStore.prototype.getCustomPropertiesOfId = function (id) {
	return Util.getCustomPropertiesOfId(this.store, id);
};<commit_msg>fix bug in chrome, not accepting prefixed tagname<commit_after>/**
 * @module libsbgn-annotations
 * @namespace libsbgn.annot
*/

var checkParams = require('./utilities').checkParams;
var $rdf = require('rdflib');
var xmldom = require('xmldom');
var N3 = require('n3');
var Util = require('./annotation-utils');

var ns = {};

/*
	EXAMPLE:

	<rdf:RDF 
		xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	    xmlns:bqmodel="http://biomodels.net/model-qualifiers/"
	    xmlns:bqbiol="http://biomodels.net/biology-qualifiers/"
	    xmlns:eisbm="http://www.eisbm.org/rdf-annotation-newt/">
		<rdf:Description rdf:about="#_000001">
			<bqmodel:is>
				<rdf:Bag>
					<rdf:li rdf:resource="http://identifiers.org/biomodels.db/BIOMD0000000004" />
				</rdf:Bag>
			</bqmodel:is>

			<bqmodel:isDescribedBy>
				<rdf:Bag>
					<rdf:li rdf:resource="http://identifiers.org/pubmed/1833774" />
				</rdf:Bag>
			</bqmodel:isDescribedBy>

			<eisbm:hasProperty>
				<rdf:Bag>
					<eisbm:item eisbm:key="data" eisbm:value="42" />
					<eisbm:item eisbm:key="data2" eisbm:value="1.23" />
				</rdf:Bag>
			</eisbm:hasProperty>

		</rdf:Description>
	</rdf:RDF> 


*/

//ns.xmlns = "http://www.sbml.org/sbml/level3/version1/render/version1";

// ------- ANNOTATION -------
/**
 * Represents the <code>&lt;annotation&gt;</code> element.
 * @class
 */
var Annotation = function (params) {
	var params = checkParams(params, ['rdfElement']);
	this.rdfElement = params.rdfElement;
};

/**
 * @param {RdfElement} rdfElement
 */
Annotation.prototype.setRdfElement = function(rdfElement) {
	this.rdfElement = rdfElement;
};

/**
 * @return {Element}
 */
Annotation.prototype.buildXmlObj = function () {
	var annotation = new xmldom.DOMImplementation().createDocument().createElement('annotation');
	if (this.rdfElement != null) {
		var rdf = this.rdfElement;
		// need to parse the string returned by serializing the rdf into a dom element
		var xmlDoc = new xmldom.DOMParser().parseFromString(rdf.toXML(), "text/xml");
		var rdfDOMElement = xmlDoc.getElementsByTagName('rdf:RDF')[0];
		annotation.appendChild(rdfDOMElement);
	}
	return annotation;
};

/**
 * @return {string}
 */
Annotation.prototype.toXML = function() {
	return new xmldom.XMLSerializer().serializeToString(this.buildXmlObj());
};

/**
 * @param {Element} xml
 * @return {Annotation}
 */
Annotation.fromXML = function (xml) {
	if (xml.tagName != 'annotation') {
		throw new Error("Bad XML provided, expected tagName annotation, got: " + xml.tagName);
	}
	var annotation = new ns.Annotation();

	/** xml.getElementsByTagName('rdf:RDF') doesn't work for Chrome */
	var rdfXML = xml.getElementsByTagName('rdf:RDF')[0] || xml.getElementsByTagName('RDF')[0];
	if (rdfXML != null) {
		var rdf = ns.RdfElement.fromXML(rdfXML);
		annotation.setRdfElement(rdf);
	}

	return annotation;
};
ns.Annotation = Annotation;
// ------- END ANNOTATION -------

// ------- GLOBALSTORE -------
var GlobalRdfStore = function () {
	this.store = N3.Store();
};

GlobalRdfStore.prototype.load = function (annotations) {
	for(var i=0; i<annotations.length; i++) {
		var annot = annotations[i];
		if(annot.rdfElement != null) {
			var rdfElement = annot.rdfElements;
			this.store.addTriples(rdfElement.store.getTriples());
		}
	}
	this.store.addPrefixes(Util.prefixes);
};

GlobalRdfStore.prototype.getCustomPropertiesOfId = function (id) {
	return Util.getCustomPropertiesOfId(this.store, id);
};
{'fraction_non_alphanumeric': 0.18059901654000893, 'fraction_numerical': 0.014155863507673968, 'mean_word_length': 4.04282494365139, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 38}, 'pii_count': 0, 'substrings_counts': 2, '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': '2103421', 'n_tokens_mistral': 2692, 'n_tokens_neox': 2439, 'n_words': 403}