<commit_before>﻿using System;
using System.IO;
using System.Reflection;

namespace Foundatio.Utility {
    public static class PathHelper {
        private const string DATA_DIRECTORY = "|DataDirectory|";

        public static string ExpandPath(string path) {
            if (String.IsNullOrEmpty(path))
                return path;
            
            if (!path.StartsWith(DATA_DIRECTORY, StringComparison.OrdinalIgnoreCase))
                return Path.GetFullPath(path);

            string dataDirectory = GetDataDirectory();
            int length = DATA_DIRECTORY.Length;
            if (path.Length <= length)
                return dataDirectory;

            string relativePath = path.Substring(length);
            char c = relativePath[0];

            if (c == Path.DirectorySeparatorChar || c == Path.AltDirectorySeparatorChar)
                relativePath = relativePath.Substring(1);

            string fullPath = Path.Combine(dataDirectory ?? String.Empty, relativePath);
            fullPath = Path.GetFullPath(fullPath);

            return fullPath;
        }

        public static string GetDataDirectory() {
            try {
                string dataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory") as string;
                if (String.IsNullOrEmpty(dataDirectory))
                    dataDirectory = Path.GetDirectoryName(typeof(PathHelper).GetTypeInfo().Assembly.Location);<commit_msg>Updated how data directory is resolved<commit_after>﻿using System;
using System.IO;
using System.Reflection;

namespace Foundatio.Utility {
    public static class PathHelper {
        private const string DATA_DIRECTORY = "|DataDirectory|";

        public static string ExpandPath(string path) {
            if (String.IsNullOrEmpty(path))
                return path;
            
            if (!path.StartsWith(DATA_DIRECTORY, StringComparison.OrdinalIgnoreCase))
                return Path.GetFullPath(path);

            string dataDirectory = GetDataDirectory();
            int length = DATA_DIRECTORY.Length;
            if (path.Length <= length)
                return dataDirectory;

            string relativePath = path.Substring(length);
            char c = relativePath[0];

            if (c == Path.DirectorySeparatorChar || c == Path.AltDirectorySeparatorChar)
                relativePath = relativePath.Substring(1);

            string fullPath = Path.Combine(dataDirectory ?? String.Empty, relativePath);
            fullPath = Path.GetFullPath(fullPath);

            return fullPath;
        }

        public static string GetDataDirectory() {
            try {
                string dataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory") as string;
                if (String.IsNullOrEmpty(dataDirectory))
                    dataDirectory = Path.GetDirectoryName(typeof(PathHelper).GetTypeInfo().Assembly.CodeBase);
{'fraction_non_alphanumeric': 0.08365019011406843, 'fraction_numerical': 0.00138264777048047, 'mean_word_length': 2.2811791383219955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6869959', 'n_tokens_mistral': 697, 'n_tokens_neox': 682, 'n_words': 160}