当前位置: 首页>>代码示例>>Java>>正文


Java NodeType类代码示例

本文整理汇总了Java中org.dswarm.graph.json.NodeType的典型用法代码示例。如果您正苦于以下问题:Java NodeType类的具体用法?Java NodeType怎么用?Java NodeType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NodeType类属于org.dswarm.graph.json包,在下文中一共展示了NodeType类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeKeyValue

import org.dswarm.graph.json.NodeType; //导入依赖的package包/类
protected void writeKeyValue(final URI predicateURI, final org.dswarm.graph.json.Node objectGDMNode) throws XMLStreamException {

			// default handling: don't export RDF types and write literal objects as XML elements
			if (!RDF.type.getURI().equals(predicateURI.toString()) && NodeType.Literal == objectGDMNode.getType()) {

				// open tag
				XMLStreamWriterUtils.writeXMLElementTag(writer, predicateURI, namespacesPrefixesMap, nameMap, isElementOpen);

				writer.writeCData(((LiteralNode) objectGDMNode).getValue());

				// close
				writer.writeEndElement();
				isElementOpen = false;
			} else {

				// TODO: ???
			}
		}
 
开发者ID:dswarm,项目名称:dswarm-graph-neo4j,代码行数:19,代码来源:PropertyGraphXMLReader.java

示例2: determineWikidataPropertyValueDataType

import org.dswarm.graph.json.NodeType; //导入依赖的package包/类
private static String determineWikidataPropertyValueDataType(final Predicate gdmPredicate, final NodeType gdmObjectType) {

		final String propertyValueDataType;

		switch (gdmObjectType) {

			case Literal:

				propertyValueDataType = DatatypeIdValue.DT_STRING;

				break;
			case Resource:

				propertyValueDataType = DatatypeIdValue.DT_ITEM;

				break;
			default:

				propertyValueDataType = DatatypeIdValue.DT_STRING;

				LOG.debug("set property value data type '{}' for property '{}', because object type is '{}'", propertyValueDataType,
						gdmPredicate.getUri(), gdmObjectType);
		}

		return propertyValueDataType;
	}
 
开发者ID:dswarm,项目名称:wikidata-d-swarm-importer,代码行数:27,代码来源:WikidataDswarmImporter.java

示例3: handleRelationship

import org.dswarm.graph.json.NodeType; //导入依赖的package包/类
@Override
public void handleRelationship(final Relationship rel) throws DMPGraphException, XMLStreamException {

	// note: we can also optionally check for the "resource property at the relationship (this property will only be
	// written right now for model that came as GDM JSON)
	if (rel.getProperty(GraphStatics.DATA_MODEL_PROPERTY).equals(prefixedDataModel)) {

		// subject => start element (???)

		//				final Node subjectNode = rel.getStartNode();
		//				final org.dswarm.graph.json.Node subjectGDMNode = propertyGraphGDMReaderHelper.readSubject(subjectNode);
		// => TODO, we need to compare the node, with the previous node, to write the content
		// (key(predicate)/value(object)) into the current element or another of this tag
		// TODO: how to determine, when we should close a tag (or parent tag etc.) => we need to keep a stack, of open
		// elements
		// predicate => XML element or XML attribute

		final String predicateString = namespaceIndex.createFullURI(rel.getType().name());
		final Tuple<Predicate, URI> predicateTuple = getPredicate(predicateString);
		final URI predicateURI = predicateTuple.v2();

		// object => XML Element value or XML attribute value or further recursion

		final Node objectNode = rel.getEndNode();
		final org.dswarm.graph.json.Node objectGDMNode = propertyGraphGDMReaderHelper.readObject(objectNode);

		writeKeyValue(predicateURI, objectGDMNode);

		// note: we can only iterate deeper into one direction, i.e., we need to cut the stream, when the object is
		// another resource => i.e. we iterate only when object are bnodes
		// TODO: what should we do with objects that are resources?
		if (objectGDMNode.getType() == NodeType.BNode) {

			// open tag
			XMLStreamWriterUtils.writeXMLElementTag(writer, predicateURI, namespacesPrefixesMap, nameMap, isElementOpen);
			isElementOpen = true;

			// continue traversal with object node
			nodeHandler.handleNode(rel.getEndNode());

			// close
			writer.writeEndElement();
			isElementOpen = false;
		}
	}
}
 
开发者ID:dswarm,项目名称:dswarm-graph-neo4j,代码行数:47,代码来源:PropertyGraphXMLReader.java

示例4: addSubject

import org.dswarm.graph.json.NodeType; //导入依赖的package包/类
private void addSubject(final Node subject) throws IOException {

		checkNotNull(subject, "couldn't write Statement JSON, because there is no subject");

		jg.writeFieldName(ModelStatics.SUBJECT_IDENTIFIER);

		final NodeType nodeType = subject.getType();

		switch (nodeType) {

			case Resource:

				addResourceNode((ResourceNode) subject);

				break;
			case BNode:

				addBNode(subject);

				break;
			default:

				throw new JsonGenerationException(String.format("couldn't write Statement JSON, didn't expect '%s' node type at subject position",
						nodeType.getName()), jg);
		}
	}
 
开发者ID:dswarm,项目名称:dswarm-gdm-java,代码行数:27,代码来源:ModelBuilder.java

示例5: addObject

import org.dswarm.graph.json.NodeType; //导入依赖的package包/类
private void addObject(final Node object) throws IOException {

		checkNotNull(object, "couldn't write Statement JSON, because there is no object");

		jg.writeFieldName(ModelStatics.OBJECT_IDENTIFIER);

		final NodeType nodeType = object.getType();

		switch (nodeType) {

			case Resource:

				addResourceNode((ResourceNode) object);

				break;
			case BNode:

				addBNode(object);

				break;
			case Literal:

				addLiteralNode((LiteralNode) object);

				break;
			default:

				throw new JsonGenerationException(String.format("couldn't write Statement JSON, didn't expect '%s' node type at subject position",
						nodeType.getName()), jg);
		}
	}
 
开发者ID:dswarm,项目名称:dswarm-gdm-java,代码行数:32,代码来源:ModelBuilder.java

示例6: processGDMStatement

import org.dswarm.graph.json.NodeType; //导入依赖的package包/类
private Optional<org.wikidata.wdtk.datamodel.interfaces.Statement> processGDMStatement(final Statement statement) {

		final Predicate gdmPredicate = statement.getPredicate();
		final Node gdmObject = statement.getObject();

		final String propertyValueDataType;

		final NodeType gdmObjectType = gdmObject.getType();

		propertyValueDataType = determineWikidataPropertyValueDataType(gdmPredicate, gdmObjectType);

		final PropertyIdValue wikidataProperty = processGDMPredicate(gdmPredicate, propertyValueDataType);

		final Optional<Value> optionalWikidataValue = processGDMObject(gdmObject);

		if (!optionalWikidataValue.isPresent()) {

			return Optional.empty();
		}

		final Value wikidataValue = optionalWikidataValue.get();

		// create property value pair
		final ValueSnak snak = Datamodel.makeValueSnak(wikidataProperty, wikidataValue);

		// process qualified attributes at GDM statement
		final Optional<List<Snak>> wikidataQualifiers = processGDMQualifiedAttributes(statement);

		final List<SnakGroup> snakGroups = new ArrayList<>();

		if (wikidataQualifiers.isPresent()) {

			final SnakGroup snakGroup = Datamodel.makeSnakGroup(wikidataQualifiers.get());

			snakGroups.add(snakGroup);
		}

		final Claim claim = Datamodel.makeClaim(null, snak, snakGroups);

		final List<Reference> references = new ArrayList<>();
		final StatementRank rank = StatementRank.NORMAL;

		// note: empty string for statement id (this should be utilised for statements that are created)
		// note: Statement references cannot be null
		// note: Statement rank cannot be null
		return Optional.ofNullable(Datamodel.makeStatement(claim, references, rank, ""));
	}
 
开发者ID:dswarm,项目名称:wikidata-d-swarm-importer,代码行数:48,代码来源:WikidataDswarmImporter.java

示例7: processGDMObject

import org.dswarm.graph.json.NodeType; //导入依赖的package包/类
private Optional<Value> processGDMObject(final Node object) {

		final NodeType objectType = object.getType();

		switch (objectType) {

			case Literal:

				final LiteralNode literalNode = (LiteralNode) object;
				final String value = literalNode.getValue();

				final String finalValue;

				if (!value.trim().isEmpty()) {

					// note: we need to trim the values; otherwise, we'll get a 'wikibase-validator-malformed-value' error
					final String trimmedValue = value.trim();

					// note: we need to cut the values, if they are longer then 400 characters; otherwise, we'll get a 'wikibase-validator-too-long' error
					finalValue = cutLongValue(trimmedValue);
				} else {

					// empty values are not possible in Wikidata - insert placeholder for now

					//finalValue = VALUE_WAS_EMPTY_ORIGINALLY;

					return Optional.empty();
				}

				return Optional.ofNullable(Datamodel.makeStringValue(finalValue));
			case Resource:

				// create ItemIdValue, i.e., create a Wikidata Item just with the Id as label

				final ResourceNode resourceNode = (ResourceNode) object;

				return Optional.ofNullable(processGDMResourceNode(resourceNode));
			default:

				// TODO throw an exception or just skip and log (i.e. these should be bnodes)
		}

		return Optional.empty();
	}
 
开发者ID:dswarm,项目名称:wikidata-d-swarm-importer,代码行数:45,代码来源:WikidataDswarmImporter.java

示例8: printGDMNode

import org.dswarm.graph.json.NodeType; //导入依赖的package包/类
private static String printGDMNode(final Node node) {

		final StringBuilder sb = new StringBuilder();

		final Long id = node.getId();

		sb.append("id = '");

		if (id != null) {

			sb.append(id);
		} else {

			sb.append("no node id available");
		}

		final NodeType nodeType = node.getType();

		switch (nodeType) {

			case Literal:

				sb.append("' :: ");

				final LiteralNode literalNode = (LiteralNode) node;
				final String value = literalNode.getValue();

				sb.append("value = '").append(value);

				break;
			case Resource:

				sb.append("' :: ");

				final ResourceNode resourceNode = (ResourceNode) node;
				final String resourceURI = resourceNode.getUri();

				sb.append("uri = '").append(resourceURI);

				break;
		}

		sb.append("' :: type = '").append(nodeType).append("'}");

		return sb.toString();
	}
 
开发者ID:dswarm,项目名称:wikidata-d-swarm-importer,代码行数:47,代码来源:WikidataDswarmImporter.java


注:本文中的org.dswarm.graph.json.NodeType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。