<commit_before>class UIC::Application
	include UIC::FileBacked

	def inspect
		"<UIC::Application '#{File.basename(file)}'#{:' FILENOTFOUND' unless file_found?}>"
	end

	attr_reader :metadata
	def initialize(metadata,uia_path)
		@metadata = metadata
		self.file = uia_path
		@assets = {}
		load_from_file if file_found?
	end

	def load_from_file
		self.doc  = Nokogiri.XML(File.read(file,encoding:'utf-8'))
		@assets   = @doc.search('assets *').map do |el|
			case el.name
				when 'behavior'     then UIC::Application::Behavior
				when 'statemachine' then UIC::Application::StateMachine
				when 'presentation' then UIC::Application::Presentation
				when 'renderplugin' then UIC::Application::RenderPlugin
			end.new(self,el)
		end.group_by{ |asset| asset.el.name }
	end

	def errors?
		!errors.empty?
	end

	def errors
		file_found? ? assets.flat_map(&:errors) : ["File not found: '#{file}'"]
	end

	def [](asset_id_or_path)
		all = assets
		if asset_id_or_path.start_with?('#')
			id = asset_id_or_path[1..-1]
			all.find{ |asset| asset.id==id }
		else
			full_path = File.expand_path(asset_id_or_path,File.dirname(file))
			all.find{ |asset| asset.file==full_path }
		end
	end

	def unused_files
		referenced_files - directory_files
	end

	def referenced_files
		# TODO: state machines can reference external scripts
		# TODO: behaviors can reference external scripts
		assets.map{ |asset| path_to(asset.src) }
		+ presentations.flat_map{ |pres| pres.presentation.referenced_files }
	end

	def assets
		@assets.values.inject(:+)
	end

	def main_presentation
		initial_id = @doc.at('assets')['initial']
		presos = presentations
		presos.find{ |pres| pres.id==initial_id } || presos.first
	end
<commit_msg>Add Application#main as convenience for Application#main_presentation<commit_after>class UIC::Application
	include UIC::FileBacked

	def inspect
		"<UIC::Application '#{File.basename(file)}'#{:' FILENOTFOUND' unless file_found?}>"
	end

	attr_reader :metadata
	def initialize(metadata,uia_path)
		@metadata = metadata
		self.file = uia_path
		@assets = {}
		load_from_file if file_found?
	end

	def load_from_file
		self.doc  = Nokogiri.XML(File.read(file,encoding:'utf-8'))
		@assets   = @doc.search('assets *').map do |el|
			case el.name
				when 'behavior'     then UIC::Application::Behavior
				when 'statemachine' then UIC::Application::StateMachine
				when 'presentation' then UIC::Application::Presentation
				when 'renderplugin' then UIC::Application::RenderPlugin
			end.new(self,el)
		end.group_by{ |asset| asset.el.name }
	end

	def errors?
		!errors.empty?
	end

	def errors
		file_found? ? assets.flat_map(&:errors) : ["File not found: '#{file}'"]
	end

	def [](asset_id_or_path)
		all = assets
		if asset_id_or_path.start_with?('#')
			id = asset_id_or_path[1..-1]
			all.find{ |asset| asset.id==id }
		else
			full_path = File.expand_path(asset_id_or_path,File.dirname(file))
			all.find{ |asset| asset.file==full_path }
		end
	end

	def unused_files
		referenced_files - directory_files
	end

	def referenced_files
		# TODO: state machines can reference external scripts
		# TODO: behaviors can reference external scripts
		assets.map{ |asset| path_to(asset.src) }
		+ presentations.flat_map{ |pres| pres.presentation.referenced_files }
	end

	def assets
		@assets.values.inject(:+)
	end

	def main_presentation
		initial_id = @doc.at('assets')['initial']
		presos = presentations
		presos.find{ |pres| pres.id==initial_id } || presos.first
	end
	alias_method :main, :main_presentation

{'fraction_non_alphanumeric': 0.12485779294653014, 'fraction_numerical': 0.0017064846416382253, 'mean_word_length': 4.564873417721519, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3792415', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1211, 'n_words': 270}