<commit_before><?php

namespace mdref;

/**
 * The RefEntry class represents a reference entry, i.e. a .md file
 */
class RefEntry
{
	/**
	 * @var \mdref\Path
	 */
	protected $path;
	
	/**
	 * @var string
	 */
	protected $entry;
	
	/**
	 * @var resource
	 */
	protected $file;
	
	/**
	 * @param \mdref\Path $path
	 * @param type $entry
	 */
	function __construct(Path $path, $entry = null) {
		$this->path = $path;
		$this->entry = trim($entry ?: $path->getPathName(), DIRECTORY_SEPARATOR);
	}
	
	/**
	 * Clean up the file handle
	 */
	function __destruct() {
		if (is_resource($this->file)) {
			fclose($this->file);
		}
	}
	
	/**
	 * Format as URL
	 * @return string
	 */
	function formatUrl() {
		return htmlspecialchars($this->entry);
	}
	
	private function joinLink(array $parts) {
		$link = "";
		$upper = ctype_upper($parts[0][0]);;
		for ($i = 0; $i < count($parts); ++$i) {
			if (!strlen($parts[$i]) || $parts[$i] === ".") {
				continue;
			}
			if (strlen($link)) {
				if ($upper && !ctype_upper($parts[$i][0])) {
					$link .= "::";
				} else {
					$link .= "\\";
				}
			}
			$link .= $parts[$i];
			$upper = ctype_upper($parts[$i][0]);
		}
		return $link;
	}

	/**
	 * Format as link text
	 * @param bool $basename whether to use the basename only
	 * @return string
	 */
	function formatLink($basename = false) {
		$link = "";
		if (strlen($this->entry)) {
			$parts = explode(DIRECTORY_SEPARATOR, $this->entry);
			$link = $basename ? end($parts) : $this->joinLink($parts);<commit_msg>prepare for general docs prepended by ": "<commit_after><?php

namespace mdref;

/**
 * The RefEntry class represents a reference entry, i.e. a .md file
 */
class RefEntry
{
	/**
	 * @var \mdref\Path
	 */
	protected $path;
	
	/**
	 * @var string
	 */
	protected $entry;
	
	/**
	 * @var resource
	 */
	protected $file;
	
	/**
	 * @param \mdref\Path $path
	 * @param type $entry
	 */
	function __construct(Path $path, $entry = null) {
		$this->path = $path;
		$this->entry = trim($entry ?: $path->getPathName(), DIRECTORY_SEPARATOR);
	}
	
	/**
	 * Clean up the file handle
	 */
	function __destruct() {
		if (is_resource($this->file)) {
			fclose($this->file);
		}
	}
	
	/**
	 * Format as URL
	 * @return string
	 */
	function formatUrl() {
		return htmlspecialchars($this->entry);
	}
	
	private function joinLink(array $parts) {
		$link = "";
		$upper = ctype_upper($parts[0][0]);;
		for ($i = 0; $i < count($parts); ++$i) {
			if (!strlen($parts[$i]) || $parts[$i] === ".") {
				continue;
			}
			if (strlen($link)) {
				if ($parts[$i][0] === ":") {
					$link = "";
				} elseif ($upper && !ctype_upper($parts[$i][0])) {
					$link .= "::";
				} else {
					$link .= "\\";
				}
			}
			$link .= trim($parts[$i], ": ");
			$upper = ctype_upper($parts[$i][0]);
		}
		return $link;
	}

	/**
	 * Format as link text
	 * @param bool $basename whether to use the basename only
	 * @return string
	 */
	function formatLink($basename = false) {
		$link = "";
		if (strlen($this->entry)) {
			$parts = explode(DIRECTORY_SEPARATOR, $this->entry);
			$link = $basename ? end($parts) : $this->joinLink($parts);
{'fraction_non_alphanumeric': 0.2077838533290447, 'fraction_numerical': 0.003538115149565777, 'mean_word_length': 2.8875, 'pattern_counts': {'":': 5, '<': 7, '<?xml version=': 0, '>': 21, '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': '2051689', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1104, 'n_words': 254}