本文整理汇总了C#中ComponentLogger.Warn方法的典型用法代码示例。如果您正苦于以下问题:C# ComponentLogger.Warn方法的具体用法?C# ComponentLogger.Warn怎么用?C# ComponentLogger.Warn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComponentLogger
的用法示例。
在下文中一共展示了ComponentLogger.Warn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportAnswerSet
/// <summary>
/// Imports the answer set.
/// </summary>
/// <param name="filepath">The filepath.</param>
/// <param name="sourceArtifacts">The source artifacts.</param>
/// <param name="sourceArtifactsFilePath">The source artifacts file path.</param>
/// <param name="targetArtifacts">The target artifacts.</param>
/// <param name="targetArtifactsFilePath">The target artifacts file path.</param>
/// <param name="logger">The logger.</param>
/// <param name="trimValues">if set to <c>true</c> [trim values].</param>
/// <returns></returns>
public static TLSimilarityMatrix ImportAnswerSet(string filepath, TLArtifactsCollection sourceArtifacts, string sourceArtifactsFilePath, TLArtifactsCollection targetArtifacts, string targetArtifactsFilePath, ComponentLogger logger, bool trimValues)
{
string friendlyAnswerSetFilename = System.IO.Path.GetFileName(filepath);
string friendlySourceArtifactsFilename = System.IO.Path.GetFileName(sourceArtifactsFilePath);
string friendlyTargetArtifactsFilename = System.IO.Path.GetFileName(targetArtifactsFilePath);
TLSimilarityMatrix answerSet = new TLSimilarityMatrix();
XPathDocument doc = new XPathDocument(filepath);
XPathNavigator nav = doc.CreateNavigator();
//read collection info
XPathNavigator iter = nav.SelectSingleNode("/answer_set/answer_info/source_artifacts_collection");
string source_artifacts_collection_id = iter.Value;
if (source_artifacts_collection_id.Equals(sourceArtifacts.CollectionId) == false)
{
throw new ArgumentException(String.Format("The answer set refers to source artifact collection with id '{0}', while loaded artifacts collection has different id '{1}'. Importing answer set from {2}",
source_artifacts_collection_id, sourceArtifacts.CollectionId, filepath));
}
iter = nav.SelectSingleNode("/answer_set/answer_info/target_artifacts_collection");
string target_artifacts_collection_id = iter.Value;
if (target_artifacts_collection_id.Equals(targetArtifacts.CollectionId) == false)
{
throw new ArgumentException(String.Format("The answer set refers to target artifact collection with id '{0}', while loaded artifacts collection has different id '{1}'. Importing answer set from {2}",
target_artifacts_collection_id, targetArtifacts.CollectionId, filepath));
}
XPathNodeIterator linksIterator = nav.Select("/answer_set/links/link");
string source_artifact_id;
string target_artifact_id;
double confidence_score;
while (linksIterator.MoveNext())
{
// Parse Source Artifact Id
iter = linksIterator.Current.SelectSingleNode("source_artifact_id");
if (iter == null)
{
throw new XmlException(String.Format("The source_artifact_id has not been provided for the link. File location: {0}", filepath));
}
source_artifact_id = iter.Value;
if (trimValues)
{
source_artifact_id = source_artifact_id.Trim();
}
if (sourceArtifacts.ContainsKey(source_artifact_id) == false)
{
logger.Warn(String.Format("The source artifact id '{0}' referenced in the answer set {1} has not been found in the source artifacts {2}. Therefore, this link has been removed in this experiment.", source_artifact_id, friendlyAnswerSetFilename, friendlySourceArtifactsFilename));
}
// Parse Target Artifact Id
iter = linksIterator.Current.SelectSingleNode("target_artifact_id");
if (iter == null)
{
throw new XmlException(String.Format("The target_artifact_id has not been provided for the link. File location: {0}", filepath));
}
target_artifact_id = iter.Value;
if (trimValues)
{
target_artifact_id = target_artifact_id.Trim();
}
if (targetArtifacts.ContainsKey(target_artifact_id) == false)
{
logger.Warn(String.Format("The target artifact id '{0}' referenced in the answer set {1} has not been found in the target artifacts {2}. Therefore, this link has been removed in this experiment.", target_artifact_id, friendlyAnswerSetFilename, friendlyTargetArtifactsFilename));
}
//Parse confidence score
iter = linksIterator.Current.SelectSingleNode("confidence_score");
if (iter == null)
{
//if confidence score is not provided set it to default value 1
confidence_score = 1.0;
}
else
{
string tmpValue = iter.Value;
if (trimValues) tmpValue = tmpValue.Trim();
if (double.TryParse(tmpValue, out confidence_score) == false)
{
throw new XmlException(String.Format("The confidence score provided for link from source artifact {0} to target artifact is in incorrect format {1}. File location: {2}", source_artifact_id, target_artifact_id, filepath));
}
}
//.........这里部分代码省略.........
示例2: build
/**
* input is a map of artifact.Id and processed text of each artifact
*
*/
public static TLDictionaryIndex build(TLArtifactsCollection setOfProcessedDocuments, ComponentLogger logger)
{
// Variables
TLTermEntry termEntry;
TLPosting posting;
double vectorLength;
// Stores the vector lenght of each document - this is used to normalize the term weights
// The vector length is the square root of the sum of the squares of all the term weights.
Dictionary<string, double> documentVectorLength = new Dictionary<string, double>();
// Creates the dictionary
TLDictionaryIndex dict = new TLDictionaryIndex();
// Iterates over all the documents
foreach (TLArtifact artifact in setOfProcessedDocuments.Values)
{
string[] terms = artifact.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (terms.Length == 0)
{
logger.Warn(String.Format("Artifact Id {0} is empty.", artifact.Id));
}
// Iterates over all the terms
foreach (string t in terms) {
// Checks if that term has already a posting
if(!dict.ContainsTermEntry(t)) {
// New term
termEntry = dict.AddTermEntry(t, 1, 1, 1.0);
posting = termEntry.AddPosting(artifact.Id, 1, 1.0);
} else {
// Existing term
termEntry = dict.GetTermEntry(t);
termEntry.TotalFrequencyAcrossArtifacts += 1;
termEntry.Weight = 1.0;
// Checks if there is already a posting for this document
if (!termEntry.ContainsPosting(artifact.Id)) {
// New posting
termEntry.NumberOfArtifactsContainingTerm += 1;
posting = termEntry.AddPosting(artifact.Id, 1, 1.0);
} else {
// Existing posting
posting = termEntry.GetPosting(artifact.Id);
posting.Frequency += 1;
posting.Weight += 1.0;
}
}
}
}
string artId;
// Now that all the counts are in, it calculates the document vector weights
foreach (TLTermEntry t in dict.TermEntries) {
foreach (TLPosting p in t.Postings) {
artId = p.ArtifactId;
vectorLength = Math.Pow(p.Frequency, 2);
if (documentVectorLength.ContainsKey(artId)) {
// The document has other terms
vectorLength += documentVectorLength[artId];
}
documentVectorLength[artId] = vectorLength;
}
}
// Finally, we need to get the square root of all entries in the document vector length
foreach (TLArtifact artifact in setOfProcessedDocuments.Values)
{
if (documentVectorLength.ContainsKey(artifact.Id))
{
vectorLength = Math.Sqrt(documentVectorLength[artifact.Id]);
// Here we update the document vector length of the dictionary - not the internal structure any more
dict.SetDocumentVectorWeight(artifact.Id, vectorLength);
}
}
return dict;
}