<commit_before>// __COPYRIGHT_START__
//
// Copyright 2009 University of Southern California. All Rights Reserved.
//
// __COPYRIGHT_END__

package edu.isi.mediator.rdf;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import edu.isi.mediator.domain.parser.DomainParser;
import edu.isi.mediator.gav.main.MediatorException;
import edu.isi.mediator.gav.util.MediatorLogger;
import edu.isi.mediator.rule.FunctionTerm;
import edu.isi.mediator.rule.LAVRule;
import edu.isi.mediator.rule.Predicate;
import edu.isi.mediator.rule.RelationPredicate;
import edu.isi.mediator.rule.Rule;
import edu.isi.mediator.rule.Term;
import edu.isi.mediator.rule.VarTerm;


/**
 * Class that provides methods for generating RDF.
 * Takes as input a domain file containing one source description (rule) and  
 * splits the rule into subrules corresponding to each variable 
 * referenced in the rule.
 * Outputs the rdf in a file or stdout.
 * Output is in N3 notation.
 * 
 * @author <NAME>(USC/ISI)
 *
 */
public class TableRDFGenerator {

	/**
	 * The source description defined in the domain model.
	 */
	private Rule tableRule;
	/**
	 * HashMap that contains <Variable, Rule> pairs, where "Rule" is a
	 * subrule that corresponds to the given variable (determined from the initial rule).
	 */
	private HashMap<String, RuleRDFGenerator> rdfGenerators = new HashMap<String, RuleRDFGenerator>();
	
	/**
	 * HashMap that contains all variables that are needed for the RDF generation subrule
	 * belonging to a variable.
	 * key: a variable value: list of additional variables needed for the rdf generation
	 * Example: rule for Phone is: Rule(Name, Phone) -> Person(uri(Name)) ^ hasPhone(uri(Name), Phone)
	 * key: Phone; value:<Name> 
	 */
	private HashMap<String, Set<String>> rdfVariables = new HashMap<String, Set<String>>();
	/**
	 * Output writer. Either to a file or to System.out
	 */
	private PrintWriter outWriter;
	
	/**
	 * Unique id, used for generating gensym URIs.
	 */
	private long uniqueId = Calendar.getInstance().getTimeInMillis();
	/**
	 * Contains mapping of prefix name to source namespace.
	 * If prefix is not used in the source desc we have only one source namespace.
	 * key=prefix; value=namespace;
	 */
	Map<String,String> sourceNamespaces;
	/**
	 * Contains mapping of prefix name to ontology namespace.
	 * If prefix is not used in the source desc we have only one ontology namespace.
	 * key=prefix; value=namespace;
	 */
	Map<String,String> ontologyNamespaces;
	
	/**
	 * Prefix used for inverse properties. When we see an inverse property <commit_msg>changed member visibility in TableRDFGenerator<commit_after>// __COPYRIGHT_START__
//
// Copyright 2009 University of Southern California. All Rights Reserved.
//
// __COPYRIGHT_END__

package edu.isi.mediator.rdf;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import edu.isi.mediator.domain.parser.DomainParser;
import edu.isi.mediator.gav.main.MediatorException;
import edu.isi.mediator.gav.util.MediatorLogger;
import edu.isi.mediator.rule.FunctionTerm;
import edu.isi.mediator.rule.LAVRule;
import edu.isi.mediator.rule.Predicate;
import edu.isi.mediator.rule.RelationPredicate;
import edu.isi.mediator.rule.Rule;
import edu.isi.mediator.rule.Term;
import edu.isi.mediator.rule.VarTerm;


/**
 * Class that provides methods for generating RDF.
 * Takes as input a domain file containing one source description (rule) and  
 * splits the rule into subrules corresponding to each variable 
 * referenced in the rule.
 * Outputs the rdf in a file or stdout.
 * Output is in N3 notation.
 * 
 * @author <NAME>(USC/ISI)
 *
 */
public class TableRDFGenerator {

	/**
	 * The source description defined in the domain model.
	 */
	protected Rule tableRule;
	/**
	 * HashMap that contains <Variable, Rule> pairs, where "Rule" is a
	 * subrule that corresponds to the given variable (determined from the initial rule).
	 */
	private HashMap<String, RuleRDFGenerator> rdfGenerators = new HashMap<String, RuleRDFGenerator>();
	
	/**
	 * HashMap that contains all variables that are needed for the RDF generation subrule
	 * belonging to a variable.
	 * key: a variable value: list of additional variables needed for the rdf generation
	 * Example: rule for Phone is: Rule(Name, Phone) -> Person(uri(Name)) ^ hasPhone(uri(Name), Phone)
	 * key: Phone; value:<Name> 
	 */
	private HashMap<String, Set<String>> rdfVariables = new HashMap<String, Set<String>>();
	/**
	 * Output writer. Either to a file or to System.out
	 */
	protected PrintWriter outWriter;
	
	/**
	 * Unique id, used for generating gensym URIs.
	 */
	private long uniqueId = Calendar.getInstance().getTimeInMillis();
	/**
	 * Contains mapping of prefix name to source namespace.
	 * If prefix is not used in the source desc we have only one source namespace.
	 * key=prefix; value=namespace;
	 */
	protected Map<String,String> sourceNamespaces;
	/**
	 * Contains mapping of prefix name to ontology namespace.
	 * If prefix is not used in the source desc we have only one ontology namespace.
	 * key=prefix; value=namespace;
	 */
	protected Map<String,String> ontologyNamespaces;
	
	/**
	 * Prefix used for inverse properties. When we see an inverse property 
{'fraction_non_alphanumeric': 0.09811711867334601, 'fraction_numerical': 0.0017274140611504578, 'mean_word_length': 4.258855585831062, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, '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': '3831670', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1660, 'n_words': 578}