本文整理汇总了C#中SemWeb.Resource类的典型用法代码示例。如果您正苦于以下问题:C# Resource类的具体用法?C# Resource怎么用?C# Resource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Resource类属于SemWeb命名空间,在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
public override bool Evaluate(Resource[] args, ref Resource @object) {
if (args.Length != 1) return false;
if (args[0] == null && @object == null) return false;
if ((args[0] != null && !(args[0] is Literal)) || (@object != null && !(@object is Literal))) return false;
try {
if (args[0] == null) {
Decimal right = (Decimal)Convert.ChangeType( ((Literal)@object).ParseValue() , typeof(Decimal) );
Decimal left = EvaluateReverse(right);
if (left == Decimal.MinValue) return false;
args[0] = Literal.FromValue(left);
return true;
} else {
Decimal left = (Decimal)Convert.ChangeType( ((Literal)args[0]).ParseValue() , typeof(Decimal) );
Decimal right = EvaluateForward(left);
if (@object == null) {
@object = Literal.FromValue(right);
return true;
} else {
Decimal right2 = (Decimal)Convert.ChangeType( ((Literal)@object).ParseValue() , typeof(Decimal) );
return right == right2;
}
}
} catch (FormatException) {
return false;
}
}
示例2: GetValueFilter
public static ValueFilter GetValueFilter(Entity predicate, Resource obj) {
if (predicate == qFilterStringContains && obj is Literal)
return new StringContainsFilter((Literal)obj);
if (obj is Literal && (predicate == qFilterLT || predicate == qFilterLE || predicate == qFilterNE || predicate == qFilterEQ || predicate == qFilterGT || predicate == qFilterGE)) {
Literal lit = (Literal)obj;
int c = 0; bool e = false;
if (predicate == qFilterLT || predicate == qFilterLE) c = -1;
if (predicate == qFilterGT || predicate == qFilterGE) c = 1;
if (predicate == qFilterLE || predicate == qFilterGE) e = true;
if (predicate == qFilterEQ) e = true;
if (lit.DataType == null || lit.DataType == "" || lit.DataType == "http://www.w3.org/2001/XMLSchema#string" || lit.DataType == "http://www.w3.org/2001/XMLSchema#normalizedString")
return new StringCompareFilter(lit, c, e);
if (lit.DataType == "http://www.w3.org/2001/XMLSchema#float" || lit.DataType == "http://www.w3.org/2001/XMLSchema#double" || lit.DataType == "http://www.w3.org/2001/XMLSchema#decimal" || lit.DataType == "http://www.w3.org/2001/XMLSchema#integer" || lit.DataType == "http://www.w3.org/2001/XMLSchema#nonPositiveInteger" || lit.DataType == "http://www.w3.org/2001/XMLSchema#negativeInteger" || lit.DataType == "http://www.w3.org/2001/XMLSchema#long" || lit.DataType == "http://www.w3.org/2001/XMLSchema#int" || lit.DataType == "http://www.w3.org/2001/XMLSchema#short" || lit.DataType == "http://www.w3.org/2001/XMLSchema#byte" || lit.DataType == "http://www.w3.org/2001/XMLSchema#nonNegativeInteger" || lit.DataType == "http://www.w3.org/2001/XMLSchema#unsignedLong" || lit.DataType == "http://www.w3.org/2001/XMLSchema#unsignedInt" || lit.DataType == "http://www.w3.org/2001/XMLSchema#unsignedShort" || lit.DataType == "http://www.w3.org/2001/XMLSchema#unsignedByte" || lit.DataType == "http://www.w3.org/2001/XMLSchema#positiveInteger")
return new NumericCompareFilter(lit, c, e);
if (lit.DataType == "http://www.w3.org/2001/XMLSchema#dateTime" || lit.DataType == "http://www.w3.org/2001/XMLSchema#date" || lit.DataType == "http://www.w3.org/2001/XMLSchema#time")
return new DateTimeCompareFilter(lit, c, e);
if (lit.DataType == "http://www.w3.org/2001/XMLSchema#duration")
return new TimeSpanCompareFilter(lit, c, e);
}
return null;
}
示例3: GetIndexArray
private StatementList GetIndexArray(Hashtable from, Resource entity) {
StatementList ret = (StatementList)from[entity];
if (ret == null) {
ret = new StatementList();
from[entity] = ret;
}
return ret;
}
示例4: Select
bool Select(Entity[] subjects, Entity[] predicates, Resource[] objects, Entity[] metas, LiteralFilter[] litFilters, int limit, StatementSink sink, bool ask) {
// TODO: Change meta into named graphs. Anything but a null or DefaultMeta
// meta returns no statements immediately.
if (metas != null && (metas.Length != 1 || metas[0] != Statement.DefaultMeta))
return false;
string query;
bool nonull = false;
if (subjects != null && subjects.Length == 1
&& predicates != null && predicates.Length == 1
&& objects != null && objects.Length == 1) {
query = "ASK WHERE { " + S(subjects[0], null) + " " + S(predicates[0], null) + " " + S(objects[0], null) + "}";
nonull = true;
} else {
if (ask)
query = "ASK { ";
else
query = "SELECT * WHERE { ";
query += S(subjects, "?subject");
query += " ";
query += S(predicates, "?predicate");
query += " ";
query += S(objects, "?object");
query += " . ";
query += SL(subjects, "?subject", false);
query += SL(predicates, "?predicate", false);
query += SL(objects, "?object", false);
query += " }";
// TODO: Pass literal filters to server.
}
if (limit >= 1)
query += " LIMIT " + limit;
Statement d = new Statement(
(subjects != null && subjects.Length == 1) ? subjects[0] : null,
(predicates != null && predicates.Length == 1) ? predicates[0] : null,
(objects != null && objects.Length == 1) ? objects[0] : null);
if (ask || nonull) {
BooleanWrap bw = new BooleanWrap();
Load(query, bw);
if (ask)
return bw.value;
else if (bw.value)
sink.Add(new Statement(subjects[0], predicates[0], objects[0]));
return false;
} else {
Load(query, new QueryToStatements(sink, litFilters, d));
return true;
}
}
示例5: Replace
public Statement Replace(Resource find, Resource replacement) {
if (replacement is Literal) {
if (find == Object)
return new Statement(Subject, Predicate, replacement, Meta);
return this;
} else {
Entity ent = (Entity)replacement;
return new Statement(
Subject == find ? ent : Subject,
Predicate == find ? ent : Predicate,
Object == find ? ent : Object,
Meta == find ? ent : Meta
);
}
}
示例6: FromSemWeb
/// <summary>
/// Helper method which converts a SemWeb resource into a PatternItem for use in a SPARQL Triple Pattern
/// </summary>
/// <param name="r">Resource</param>
/// <param name="mapping">Mapping of Variables & Blank Nodes to Pattern Items</param>
/// <param name="g">Graph</param>
/// <returns></returns>
private PatternItem FromSemWeb(Resource r, IGraph g, Dictionary<String, PatternItem> mapping)
{
if (r is Variable)
{
if (mapping.ContainsKey(r.ToString()))
{
return mapping[r.ToString()];
}
else
{
PatternItem temp = new VariablePattern(r.ToString());
mapping.Add(r.ToString(), temp);
return temp;
}
}
else if (r is BNode)
{
if (mapping.ContainsKey(r.ToString()))
{
return mapping[r.ToString()];
}
else
{
PatternItem temp = new BlankNodePattern(r.ToString().Substring(2));
mapping.Add(r.ToString(), temp);
return temp;
}
}
else
{
return new NodeMatchPattern(SemWebConverter.FromSemWeb(r, this.GetMapping(g)));
}
}
示例7: FromSemWeb
/// <summary>
/// Converts a SemWeb Resource into a dotNetRDF Node
/// </summary>
/// <param name="r">Resource</param>
/// <param name="mapping">Mapping of Blank Nodes</param>
/// <returns></returns>
public static INode FromSemWeb(Resource r, SemWebMapping mapping)
{
if (r is Entity)
{
return FromSemWebEntity((Entity)r, mapping);
}
else if (r is Literal)
{
Literal lit = (Literal)r;
if (lit.DataType != null)
{
return mapping.Graph.CreateLiteralNode(lit.Value, new Uri(lit.DataType));
}
else if (lit.Language != null)
{
return mapping.Graph.CreateLiteralNode(lit.Value, lit.Language);
}
else
{
return mapping.Graph.CreateLiteralNode(lit.Value);
}
}
else
{
throw new RdfException("Cannot convert an unknown SemWeb Resource type to a dotNetRDF Node");
}
}
示例8: ReadPredicate
private char ReadPredicate(Resource subject, ParseContext context) {
bool reverse;
Location loc = context.Location;
Resource predicate = ReadResource(context, out reverse);
if (predicate == null) OnError("Expecting a predicate", loc);
if (predicate is Literal) OnError("Predicates cannot be literals", loc);
char punctuation = ',';
while (punctuation == ',') {
ReadObject(subject, (Entity)predicate, context, reverse);
loc = context.Location;
punctuation = ReadPunc(context.source);
}
if (punctuation != '.' && punctuation != ';' && punctuation != ']' && punctuation != '}')
OnError("Expecting a period, semicolon, comma, or close-bracket but found '" + punctuation + "'", loc);
return punctuation;
}
示例9: Contains
/// <summary>
/// Returns whether the Store contains Statements which contain the given Resource
/// </summary>
/// <param name="resource">Resource</param>
/// <returns></returns>
public bool Contains(Resource resource)
{
//Implemented as a SPARQL ASK
String query = "ASK WHERE {{" + resource.ToString() + " ?p ?o} UNION {?s " + resource.ToString() + " ?o} UNION {?s ?p " + resource.ToString() + "}}";
return this.ContainsInternal(query);
}
示例10: Run
public override void Run(SelectableSource source, QueryResultSink resultsink)
{
if (!(query is SelectQuery))
throw new InvalidOperationException("Only SELECT queries are supported by this method (" + query.GetType() + ").");
// Perform the query
SelectQuery squery = (SelectQuery)query;
RdfSourceWrapper sourcewrapper = BindLogic(source);
RdfBindingSet results;
try {
results = squery.execute(sourcewrapper);
} catch (name.levering.ryan.sparql.common.QueryException e) {
throw new QueryExecutionException("Error executing query: " + e.Message, e);
}
// Prepare binding objects
java.util.List vars = results.getVariables();
SparqlVariable[] svars = new SparqlVariable[vars.size()];
SemWebVariable[] vars2 = new SemWebVariable[vars.size()];
for (int i = 0; i < svars.Length; i++) {
svars[i] = (SparqlVariable)vars.get(i);
vars2[i] = new SemWebVariable(svars[i].getName());
}
// Initialize the result sink
resultsink.Init(vars2); // set distinct and ordered
// Set the comments
resultsink.AddComments(queryString + "\n");
resultsink.AddComments(sourcewrapper.GetLog());
// Iterate the bindings
java.util.Iterator iter = results.iterator();
long ctr = -1, ctr2 = 0;
while (iter.hasNext()) {
RdfBindingRow row = (RdfBindingRow)iter.next();
// Since SPARQL processing may be lazy-delayed,
// add any new comments that might have been logged.
resultsink.AddComments(sourcewrapper.GetLog());
ctr++;
if (ctr < ReturnStart && ReturnStart != -1) continue;
Resource[] bindings = new Resource[vars2.Length];
for (int i = 0; i < bindings.Length; i++) {
Resource r = sourcewrapper.ToResource(row.getValue(svars[i]));
r = sourcewrapper.Persist(r);
bindings[i] = r;
}
resultsink.AddComments(sourcewrapper.GetLog());
resultsink.Add(new VariableBindings(vars2, bindings));
ctr2++;
if (ctr2 >= ReturnLimit && ReturnLimit != -1) break;
}
resultsink.AddComments(sourcewrapper.GetLog());
// Close the result sink.
resultsink.Finished();
}
示例11: GetIterator
private java.util.Iterator GetIterator(Entity[] subjects, Entity[] predicates, Resource[] objects, Entity[] metas, object[] litFilters, int limit)
{
if (subjects == null && predicates == null && objects == null && limit == -1)
throw new QueryExecutionException("Query would select all statements in the store!");
if (subjects != null) Depersist(subjects);
if (predicates != null) Depersist(predicates);
if (objects != null) Depersist(objects);
if (metas != null) Depersist(metas);
if (subjects != null && subjects.Length == 0) return new EmptyIterator();
if (predicates != null && predicates.Length == 0) return new EmptyIterator();
if (objects != null && objects.Length == 0) return new EmptyIterator();
if (metas != null && metas.Length == 0) return new EmptyIterator();
SelectFilter filter = new SelectFilter(subjects, predicates, objects, metas);
if (litFilters != null) {
filter.LiteralFilters = new LiteralFilter[litFilters.Length];
for (int i = 0; i < litFilters.Length; i++)
filter.LiteralFilters[i] = (LiteralFilter)litFilters[i];
}
if (limit == 0)
filter.Limit = 1;
else if (limit > 0)
filter.Limit = limit;
return new StatementIterator(source, filter, this);
}
示例12: Wrap
public static org.openrdf.model.Value Wrap(Resource res) {
if (res is Literal)
return new LiteralWrapper((Literal)res);
else if (res.Uri == null)
return new BNodeWrapper((BNode)res);
else
return new URIWrapper((Entity)res);
}
示例13: Persist
public Resource Persist(Resource r) {
if (!(r is BNode) || !sparql.AllowPersistBNodes) return r;
if (!(source is SupportsPersistableBNodes)) return r;
SupportsPersistableBNodes spb = (SupportsPersistableBNodes)source;
string guid = spb.GetStoreGuid();
if (guid == null) return r;
string id = spb.GetNodeId((BNode)r);
if (id == null) return r;
return new Entity(Sparql.BNodePersistUri + guid + ":" + id);
}
示例14: Depersist
public Resource Depersist(Resource r) {
if (r.Uri == null || !sparql.AllowPersistBNodes) return r;
if (!(source is SupportsPersistableBNodes)) return r;
if (!r.Uri.StartsWith(Sparql.BNodePersistUri)) return r;
SupportsPersistableBNodes spb = (SupportsPersistableBNodes)source;
string uri = r.Uri;
string guid = uri.Substring(Sparql.BNodePersistUri.Length);
int c = guid.IndexOf(':');
if (c > 0) {
string id = guid.Substring(c+1);
guid = guid.Substring(0, c);
if (spb.GetStoreGuid() != null && guid == spb.GetStoreGuid()) {
BNode node = spb.GetNodeFromId(id);
if (node != null)
return node;
}
}
return r;
}
示例15: ToResources
public Resource[] ToResources(org.openrdf.model.Value[] ents) {
if (ents == null) return null;
Resource[] ret = new Resource[ents.Length];
for (int i = 0; i < ents.Length; i++)
ret[i] = ToResource(ents[i]);
return ret;
}