public Document GetOrCreateDocument(DocumentParser documentParser/*, LinkType linkType*/)
{
Document result = (Document)GetArgumentObject(SemanticOperationNamedArguments.Document);
// get the ancestor container
Document sourceDocument = ResolveSourceDocument();
// get the seed. Non null only for search types .
//Seed seed = documentParser.getSeed();
if (result == null)
{
Object outlinkPurlObject = GetArgumentObject(SemanticOperationNamedArguments.Location);
if (outlinkPurlObject != null)
{
ParsedUri outlinkPurl = ((MetadataParsedURL)outlinkPurlObject).Value;
//result = sessionScope.GetOrConstructDocument(outlinkPurl);
}
}
if (result == null)
result = sourceDocument; //direct binding?!
if (result != null /*&& !result.IsRecycled()*/ && (result.Location != null))
{
result.SemanticsSessionScope = (SemanticsSessionScope)sessionScope;
MetadataNS.Metadata mixin = (MetadataNS.Metadata)GetArgumentObject(SemanticOperationNamedArguments.Mixin);
if (mixin != null)
result.AddMixin(mixin);
/* if (seed != null)
{
seed.bindToDocument(result);
}
*/
MetadataString anchorText = (MetadataString)GetArgumentObject(SemanticOperationNamedArguments.AnchorText);
// create anchor text from Document title if there is none passed in directly, and we won't
// be setting metadata
// if (anchorText == null)
// anchorText = result.Title;
// work to avoid honey pots!
MetadataString anchorContextString = (MetadataString)GetArgumentObject(SemanticOperationNamedArguments.AnchorContext);
bool citationSignificance = GetArgumentBoolean(SemanticOperationNamedArguments.CitationSignificance, false);
float significanceVal = GetArgumentFloat(SemanticOperationNamedArguments.SignificanceValue, 1);
bool traversable = GetArgumentBoolean(SemanticOperationNamedArguments.Traversable, true);
bool ignoreContextForTv = GetArgumentBoolean(SemanticOperationNamedArguments.IgnoreContextForTv, false);
ParsedUri location = result.Location.Value;
/* if (traversable)
{
Seeding seeding = sessionScope.getSeeding();
if (seeding != null)
seeding.traversable(location);
}
bool anchorIsInSource = false;
if (sourceDocument != null)
{
// Chain the significance from the ancestor
SemanticInLinks sourceInLinks = sourceDocument.getSemanticInlinks();
if (sourceInLinks != null)
{
significanceVal *= sourceInLinks.meanSignificance();
anchorIsInSource = sourceInLinks.containsKey(location);
}
}
if(! anchorIsInSource)
{
//By default use the boost, unless explicitly stated in this site's MMD
SemanticsSite site = result.GetSite;
boolean useSemanticBoost = !site.ignoreSemanticBoost();
if (citationSignificance)
linkType = LinkType.CITATION_SEMANTIC_ACTION;
else if (useSemanticBoost && linkType == LinkType.OTHER_SEMANTIC_ACTION)
linkType = LinkType.SITE_BOOSTED_SEMANTIC_ACTION;
SemanticAnchor semanticAnchor = new SemanticAnchor(linkType, location, null,
sourceDocument.getLocation(), significanceVal);// this is not fromContentBody,
// but is fromSemanticActions
if(ignoreContextForTv)
semanticAnchor.addAnchorContextToTV(anchorText, null);
else
semanticAnchor.addAnchorContextToTV(anchorText, anchorContextString);
result.addSemanticInlink(semanticAnchor, sourceDocument);
}
else
{
Console.WriteLine("Ignoring inlink, because ancestor contains the same, we don't want cycles in the graph just yet: sourceContainer -- outlinkPurl :: " + sourceDocument + " -- " + location);
}*/
}
// adding the return value to map
Scope<Object> semanticActionVariableMap = SemanticOperationHandler.SemanticOperationVariableMap;
if (semanticActionVariableMap != null)
{
if (GetReturnObjectName() != null)
semanticActionVariableMap.Put(GetReturnObjectName(), result);
}
else
Debug.WriteLine("semanticActionVariableMap is null !! Not frequently reproducible either. Place a breakpoint here to try fixing it next time.");
// set flags if any
// setFlagIfAny(action, localContainer);
// return the value. Right now no need for it. Later it might be used.
return result;
}