<commit_before><?php
/**
 * @package plugins.caption
 * @subpackage lib
 */
class dfxpCaptionsContentManager extends kCaptionsContentManager
{
	/* (non-PHPdoc)
	 * @see kCaptionsContentManager::parse()
	 */
	public function parse($content)
	{
		$xml = new DOMDocument();
		try{
			$xml->loadXML($content);
		}
		catch(Exception $e)
		{
			KalturaLog::err($e->getMessage());
			return array();
		}
		
		$elements = $xml->getElementsByTagName('p');
		if(!$elements->length)
		{
			KalturaLog::err("XML element <p> not found");
			return array();
		}
			
		$itemsData = array();
		foreach($elements as $element)
		{
			/* @var $element DOMElement */
			$startTime = kXml::timeToInteger($element->getAttribute('begin'));
			$endTime = $startTime;
			if($element->hasAttribute('end'))
			{
				$endTime = kXml::timeToInteger($element->getAttribute('end'));
			}
			elseif($element->hasAttribute('dur'))
			{
				$duration = floatval($element->getAttribute('dur')) * 1000;
				$endTime = $startTime + $duration;
			}
			$itemsData[] = array(
				'startTime' => $startTime,
				'endTime' => $endTime, 
				'content' => $element->textContent,
			);
		}
		
		return $itemsData;
	}
	
	/* (non-PHPdoc)
	 * @see kCaptionsContentManager::getContent()
	 */
	public function getContent($content)
	{
		$xml = new DOMDocument();
		try{
			$xml->loadXML($content);
		}<commit_msg>qnd: support other time formants<commit_after><?php
/**
 * @package plugins.caption
 * @subpackage lib
 */
class dfxpCaptionsContentManager extends kCaptionsContentManager
{
	/* (non-PHPdoc)
	 * @see kCaptionsContentManager::parse()
	 */
	public function parse($content)
	{
		$xml = new DOMDocument();
		try
		{
			$xml->loadXML($content);
		}
		catch(Exception $e)
		{
			KalturaLog::err($e->getMessage());
			return array();
		}
		
		$elements = $xml->getElementsByTagName('p');
		if(! $elements->length)
		{
			KalturaLog::err("XML element <p> not found");
			return array();
		}
		
		$itemsData = array();
		foreach($elements as $element)
		{
			/* @var $element DOMElement */
			$startTime = $this->parseStrTTTime($element->getAttribute('begin'));
			$endTime = $startTime;
			if($element->hasAttribute('end'))
			{
				$endTime = $this->parseStrTTTime($element->getAttribute('end'));
			}
			elseif($element->hasAttribute('dur'))
			{
				$duration = floatval($element->getAttribute('dur')) * 1000;
				$endTime = $startTime + $duration;
			}
			$itemsData[] = array('startTime' => $startTime, 'endTime' => $endTime, 'content' => $element->textContent);
		}
		
		return $itemsData;
	}
	
	private function parseStrTTTime($timeStr)
	{
		$matches = null;
		if(preg_match('/(\d+)s/', $timeStr))
			return intval($matches[1]) * 1000;
			
		return kXml::timeToInteger($timeStr);
	}
	
	/* (non-PHPdoc)
	 * @see kCaptionsContentManager::getContent()
	 */
	public function getContent($content)
	{
		$xml = new DOMDocument();
		try
		{
			$xml->loadXML($content);
		}
{'fraction_non_alphanumeric': 0.18085470085470085, 'fraction_numerical': 0.0044444444444444444, 'mean_word_length': 3.86046511627907, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '6204107', 'n_tokens_mistral': 1169, 'n_tokens_neox': 992, 'n_words': 172}