<commit_before>angular.module('myapp').factory('ConversorService', function(ConceptualService, $uibModal, $q, $log){

		var modelGraph;
		var cs = ConceptualService;
		var ls = {};
		var conversion = {};

		var entityTableMap = new Map();
		var tableEntityMap = new Map();

		var tables = [];

		_startConversion = function(){
			_toLogic(conversion);
		}

		_toLogic = function(graph, logicService) {

			ls = logicService;

			return $q(function(resolve, reject) {

				tables = [];

				modelGraph = graph;
				conversion = graph;

				var cell_tables = [];
				var cell_relations = [];

				var all = modelGraph.toJSON().cells;

				for (element of all) {
					if(element.type === 'erd.Entity') {
						cell_tables.push(element);
					}

					if(element.type === 'erd.Relationship') {
						cell_relations.push(element);
					}
				}

				(function iterate() {

						if(cell_tables.length == 0){
							var relation_promise = buildRelations(cell_relations);
							relation_promise.then(function() {
								resolve(tables);
							});
						}

						var element = cell_tables.shift();

						if(element != null) {
							var promise = buildTable(element, modelGraph.getNeighbors(element));
							promise.then(function(editedTable) {
								var newTable = ls.insertTable(editedTable);
								entityTableMap.set(element.id, newTable);
								tableEntityMap.set(newTable.id, element.id);
								iterate();
							});
						}

					})();

				});
		};

		buildRelations = function(relations) {

			console.log("relations: ", relations);

			return $q(function(resolve){

				(function iterate() {

					if(relations.length == 0){

						resolve();

					} else {

						var relation = relations.shift();

						var links = modelGraph.getConnectedLinks(relation);

						var relationType = getRelationType(links);

						switch (relationType.type) {
							case "nn":
								createTableFromRelation(relation).then(function(){
									iterate();
								});
								break;
							case "1n":
								treatN1case(relation, links).then(function(){
									iterate();
								});
								break;
							case "n1":
								treatN1case(relation, links).then(function(){
									iterate();
								});
								break;
							case "11":
								treat11case(relation, links).then(function(){
									iterate();
								});
								break;
							default:
								iterate();
						}

					}<commit_msg>Corrigindo conversão relacionamento ternario +<commit_after>angular.module('myapp').factory('ConversorService', function(ConceptualService, $uibModal, $q, $log){

		var modelGraph;
		var cs = ConceptualService;
		var ls = {};
		var conversion = {};

		var entityTableMap = new Map();
		var tableEntityMap = new Map();

		var tables = [];

		_startConversion = function(){
			_toLogic(conversion);
		}

		_toLogic = function(graph, logicService) {

			ls = logicService;

			return $q(function(resolve, reject) {

				tables = [];

				modelGraph = graph;
				conversion = graph;

				var cell_tables = [];
				var cell_relations = [];

				var all = modelGraph.toJSON().cells;

				for (element of all) {
					if(element.type === 'erd.Entity') {
						cell_tables.push(element);
					}

					if(element.type === 'erd.Relationship') {
						cell_relations.push(element);
					}
				}

				(function iterate() {

						if(cell_tables.length == 0){
							var relation_promise = buildRelations(cell_relations);
							relation_promise.then(function() {
								resolve(tables);
							});
						}

						var element = cell_tables.shift();

						if(element != null) {
							var promise = buildTable(element, modelGraph.getNeighbors(element));
							promise.then(function(editedTable) {
								var newTable = ls.insertTable(editedTable);
								entityTableMap.set(element.id, newTable);
								tableEntityMap.set(newTable.id, element.id);
								iterate();
							});
						}

					})();

				});
		};

		buildRelations = function(relations) {

			console.log("relations: ", relations);

			return $q(function(resolve){

				(function iterate() {

					if(relations.length == 0){

						resolve();

					} else {

						var relation = relations.shift();

						var links = modelGraph.getConnectedLinks(relation);

						var relationType = getRelationType(links);

						if(relationType.quantity > 2) {

							createTableFromRelation(relation).then(function(){
								iterate();
							});
							
						} else {
							switch (relationType.type) {
								case "nn":
									createTableFromRelation(relation).then(function(){
										iterate();
									});
									break;
								case "1n":
									treatN1case(relation, links).then(function(){
										iterate();
									});
									break;
								case "n1":
									treatN1case(relation, links).then(function(){
										iterate();
									});
									break;
								case "11":
									treat11case(relation, links).then(function(){
										iterate();
									});
									break;
								default:
									iterate();
							}
						}

					}
{'fraction_non_alphanumeric': 0.1372431677638141, 'fraction_numerical': 0.004189108318372232, 'mean_word_length': 2.2921864740643465, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 4, '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': '4027410', 'n_tokens_mistral': 2373, 'n_tokens_neox': 1438, 'n_words': 273}