<commit_before>﻿using System;
using Terradue.OpenSearch.Result;
using System.Xml.XPath;
using Terradue.ServiceModel.Syndication;
using System.Linq;
using System.Xml.Linq;
using System.Xml;
using System.Collections.Generic;
using System.Collections.Specialized;
using Terradue.OpenSearch.Schema;
using Terradue.OpenSearch;
using System.Text.RegularExpressions;

namespace Terradue.Metadata.EarthObservation {
    public static class EarthObservationOpenSearchResultHelpers {

        public static void RestoreEnclosure(IOpenSearchResultCollection result) {
            foreach (var item in result.Items) {
                RestoreEnclosure(item);
            }
        }



        public static void RestoreEnclosure(IOpenSearchResultItem item) {

            var matchLinks = item.Links.Where(l => l.RelationshipType == "enclosure").ToArray();
            if (matchLinks.Count() == 0) {
                foreach (var eo in item.ElementExtensions) {
                    XElement eoElement = (XElement)XElement.ReadFrom(eo.GetReader());
                    if (eoElement.Name.LocalName == "EarthObservation") {
                        var result = eoElement.XPathSelectElement(string.Format("om:result/eop:EarthObservationResult/eop:product/eop:ProductInformation", EONamespaces.TypeNamespaces[eo.OuterNamespace]), EONamespaces.GetXmlNamespaceManager(eoElement));
                        if (result != null) {
                            var link = result.XPathSelectElement("eop:fileName/ows:ServiceReference", EONamespaces.GetXmlNamespaceManager(result));
                            if (link != null && link.Attribute(XName.Get("href", "http://www.w3.org/1999/xlink")) != null) {
                                long size = 0;
                                var sizeElement = result.XPathSelectElement("eop:size", EONamespaces.GetXmlNamespaceManager(result));
                                if (sizeElement != null)
                                    long.TryParse(sizeElement.Value, out size);<commit_msg>enclosure with negative size handled<commit_after>﻿using System;
using Terradue.OpenSearch.Result;
using System.Xml.XPath;
using Terradue.ServiceModel.Syndication;
using System.Linq;
using System.Xml.Linq;
using System.Xml;
using System.Collections.Generic;
using System.Collections.Specialized;
using Terradue.OpenSearch.Schema;
using Terradue.OpenSearch;
using System.Text.RegularExpressions;

namespace Terradue.Metadata.EarthObservation {
    public static class EarthObservationOpenSearchResultHelpers {

        public static void RestoreEnclosure(IOpenSearchResultCollection result) {
            foreach (var item in result.Items) {
                RestoreEnclosure(item);
            }
        }



        public static void RestoreEnclosure(IOpenSearchResultItem item) {

            var matchLinks = item.Links.Where(l => l.RelationshipType == "enclosure").ToArray();
            if (matchLinks.Count() == 0) {
                foreach (var eo in item.ElementExtensions) {
                    XElement eoElement = (XElement)XElement.ReadFrom(eo.GetReader());
                    if (eoElement.Name.LocalName == "EarthObservation") {
                        var result = eoElement.XPathSelectElement(string.Format("om:result/eop:EarthObservationResult/eop:product/eop:ProductInformation", EONamespaces.TypeNamespaces[eo.OuterNamespace]), EONamespaces.GetXmlNamespaceManager(eoElement));
                        if (result != null) {
                            var link = result.XPathSelectElement("eop:fileName/ows:ServiceReference", EONamespaces.GetXmlNamespaceManager(result));
                            if (link != null && link.Attribute(XName.Get("href", "http://www.w3.org/1999/xlink")) != null) {
                                long size = 0;
                                var sizeElement = result.XPathSelectElement("eop:size", EONamespaces.GetXmlNamespaceManager(result));
                                if (sizeElement != null)
                                    long.TryParse(sizeElement.Value, out size);
                                if (size < 0)
                                    size = 0;
{'fraction_non_alphanumeric': 0.09649334945586457, 'fraction_numerical': 0.0038694074969770256, 'mean_word_length': 2.4069192751235584, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4946505', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1063, 'n_words': 200}