<commit_before>﻿using System;
using System.IO;
using System.Linq;
using System.Reflection;
using TCode.r2rml4net.Extensions;
using TCode.r2rml4net.Mapping;
using TCode.r2rml4net.Mapping.Fluent;
using VDS.RDF;
using VDS.RDF.Nodes;
using VDS.RDF.Parsing;
using VDS.RDF.Parsing.Tokens;
using VDS.RDF.Query.Expressions.Primary;

namespace Slp.Evi.Storage.Utils
{
    /// <summary>
    /// Extension class to fix issues in the used libraries
    /// </summary>
    public static class FixesExtensions
    {
        /// <summary>
        /// Gets the node for the specified term.
        /// </summary>
        /// <param name="term">The term.</param>
        /// <returns>The node.</returns>
        public static IValuedNode Node(this ConstantTerm term)
        {
            var property = typeof(ConstantTerm).GetProperty("Node", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Default | BindingFlags.Instance);
            return (IValuedNode)property.GetValue(term);
        }

        /// <summary>
        /// Gets the specified literal term map (parsed).
        /// </summary>
        public static ParsedLiteralParts Parsed(this ILiteralTermMap literalTermMap)
        {
            var literalNode = literalTermMap.Node.GetObjects("rr:constant").FirstOrDefault() as ILiteralNode;

            if (literalNode != null)
            {
                return new ParsedLiteralParts(literalNode.Value, literalNode.DataType, literalNode.Language);
            }
            else
            {
                throw new Exception("Cannot get the constant");
            }
        }

        public static ITriplesMapConfiguration GetTriplesMapConfiguration(this IMapBase mapBase)
        {
            var property = typeof(BaseConfiguration).GetProperty("TriplesMap", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Default | BindingFlags.Instance);
            return (ITriplesMapConfiguration)property.GetValue(mapBase);
        }
    }

    /// <summary>
    /// Parsed literal parts.
    /// </summary>
    public class ParsedLiteralParts
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ParsedLiteralParts"/> class.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="type">The type.</param>
        /// <param name="languageTag">The language tag.</param>
        public ParsedLiteralParts(string value, Uri type, string languageTag)
        {
            LanguageTag = languageTag;
            Type = type;
            Value = value;
        }

        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <value>The value.</value>
        public string Value { get; private set; }

        /// <summary>
        /// Gets the type.
        /// </summary>
        /// <value>The type.</value>
        public Uri Type { get; private set; }

        /// <summary>
        /// Gets the language tag.
        /// </summary>
        /// <value>The language tag.</value>
        public string LanguageTag { get; private set; }
    }
}
<commit_msg>Missing comment.<commit_after>﻿using System;
using System.IO;
using System.Linq;
using System.Reflection;
using TCode.r2rml4net.Extensions;
using TCode.r2rml4net.Mapping;
using TCode.r2rml4net.Mapping.Fluent;
using VDS.RDF;
using VDS.RDF.Nodes;
using VDS.RDF.Parsing;
using VDS.RDF.Parsing.Tokens;
using VDS.RDF.Query.Expressions.Primary;

namespace Slp.Evi.Storage.Utils
{
    /// <summary>
    /// Extension class to fix issues in the used libraries
    /// </summary>
    public static class FixesExtensions
    {
        /// <summary>
        /// Gets the node for the specified term.
        /// </summary>
        /// <param name="term">The term.</param>
        /// <returns>The node.</returns>
        public static IValuedNode Node(this ConstantTerm term)
        {
            var property = typeof(ConstantTerm).GetProperty("Node", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Default | BindingFlags.Instance);
            return (IValuedNode)property.GetValue(term);
        }

        /// <summary>
        /// Gets the specified literal term map (parsed).
        /// </summary>
        public static ParsedLiteralParts Parsed(this ILiteralTermMap literalTermMap)
        {
            var literalNode = literalTermMap.Node.GetObjects("rr:constant").FirstOrDefault() as ILiteralNode;

            if (literalNode != null)
            {
                return new ParsedLiteralParts(literalNode.Value, literalNode.DataType, literalNode.Language);
            }
            else
            {
                throw new Exception("Cannot get the constant");
            }
        }

        /// <summary>
        /// Gets the triples map configuration.
        /// </summary>
        /// <param name="mapBase">The map base.</param>
        /// <returns>ITriplesMapConfiguration.</returns>
        public static ITriplesMapConfiguration GetTriplesMapConfiguration(this IMapBase mapBase)
        {
            var property = typeof(BaseConfiguration).GetProperty("TriplesMap", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Default | BindingFlags.Instance);
            return (ITriplesMapConfiguration)property.GetValue(mapBase);
        }
    }

    /// <summary>
    /// Parsed literal parts.
    /// </summary>
    public class ParsedLiteralParts
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ParsedLiteralParts"/> class.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="type">The type.</param>
        /// <param name="languageTag">The language tag.</param>
        public ParsedLiteralParts(string value, Uri type, string languageTag)
        {
            LanguageTag = languageTag;
            Type = type;
            Value = value;
        }

        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <value>The value.</value>
        public string Value { get; private set; }

        /// <summary>
        /// Gets the type.
        /// </summary>
        /// <value>The type.</value>
        public Uri Type { get; private set; }

        /// <summary>
        /// Gets the language tag.
        /// </summary>
        /// <value>The language tag.</value>
        public string LanguageTag { get; private set; }
    }
}

{'fraction_non_alphanumeric': 0.122669591101363, 'fraction_numerical': 0.0018799937333542221, 'mean_word_length': 1.9901639344262294, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 75, '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': '5561814', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1695, 'n_words': 419}