@Nullable @Override public String apply(@Nullable EntityType input) { return input == null ? null : input.getName(); } };
@Override public void describeTo(DescriptionWriter writer) { for (EntityType etype: Ordering.natural() .onResultOf(Entities.entityTypeNameFunction()) .sortedCopy(storage.keySet())) { writer.putField(etype.getName(), storage.get(etype)); } } }
/** * Look up the defaults for a particular entity type. * @param type The entity type. * @return The defaults. */ @Nullable public static EntityDefaults lookup(EntityType type) { // TODO Cache these defaults String name = type.getName(); String path = String.format("META-INF/lenskit/entity-defaults/%s.yaml", name); try (InputStream stream = ClassLoaders.inferDefault(EntityDefaults.class) .getResourceAsStream(path)) { if (stream == null) { return null; } ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); DefaultsBean bean = mapper.readValue(stream, DefaultsBean.class); return fromBean(type, bean); } catch (IOException e) { throw new UncheckedIOException("error defaults for " + type, e); } }
@Override public ObjectNode toJSON() { JsonNodeFactory nf = JsonNodeFactory.instance; ObjectNode json = nf.objectNode(); json.put("format", "json"); json.put("entity_type", entityType.getName()); if (!attributes.isEmpty()) { ObjectNode attrNode = json.putObject("attributes"); for (Map.Entry<String,TypedName<?>> attr: attributes.entrySet()) { ObjectNode an = attrNode.putObject(attr.getKey()); an.put("name", attr.getValue().getName()); an.put("type", TypeUtils.makeTypeName(attr.getValue().getType())); } } return json; }
json.put("format", "delimited"); json.put("delimiter", delimiter); json.put("entity_type", entityType.getName()); json.put("base_id", getBaseId()); if (readHeader) {
node.set("format", fac.textNode("tsv")); node.set("file", fac.textNode(ITEM_FILE_NAME)); node.set("entity_type", fac.textNode(CommonTypes.ITEM.getName())); ArrayNode cols = fac.arrayNode(); cols.add(CommonAttributes.ENTITY_ID.getName());
train.set("file", nf.textNode(outputDir.relativize(trainFiles.get(i)).toString())); train.set("format", nf.textNode("csv")); train.set("entity_type", nf.textNode(entityType.getName())); train.set("metadata", mapper.valueToTree(meta)); trainList.add(train); test.set("file", nf.textNode(outputDir.relativize(testFiles.get(i)).toString())); test.set("format", nf.textNode("csv")); test.set("entity_type", nf.textNode(entityType.getName())); test.set("metadata", mapper.valueToTree(meta)); mapper.writeValue(testManifestFiles.get(i).toFile(), test);
@Test public void testCreate() { EntityType wombat = EntityType.forName("wombat"); EntityType wombat2 = EntityType.forName("wombat"); EntityType woozle = EntityType.forName("woozle"); assertThat(wombat.getName(), equalTo("wombat")); assertThat(woozle.getName(), equalTo("woozle")); assertThat(wombat, equalTo(wombat2)); assertThat(wombat, sameInstance(wombat2)); assertThat(wombat, not(equalTo(woozle))); }
@Test public void testCaseNorm() { EntityType wombat = EntityType.forName("Wombat"); assertThat(wombat.getName(), equalTo("wombat")); assertThat(EntityType.forName("wombaT"), sameInstance(wombat)); } }
@Nullable @Override public String apply(@Nullable EntityType input) { return input == null ? null : input.getName(); } };
@Override public void describeTo(DescriptionWriter writer) { for (EntityType etype: Ordering.natural() .onResultOf(Entities.entityTypeNameFunction()) .sortedCopy(storage.keySet())) { writer.putField(etype.getName(), storage.get(etype)); } } }
/** * Look up the defaults for a particular entity type. * @param type The entity type. * @return The defaults. */ @Nullable public static EntityDefaults lookup(EntityType type) { // TODO Cache these defaults String name = type.getName(); String path = String.format("META-INF/lenskit/entity-defaults/%s.yaml", name); try (InputStream stream = ClassLoaders.inferDefault(EntityDefaults.class) .getResourceAsStream(path)) { if (stream == null) { return null; } ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); DefaultsBean bean = mapper.readValue(stream, DefaultsBean.class); return fromBean(type, bean); } catch (IOException e) { throw new UncheckedIOException("error defaults for " + type, e); } }
@Override public ObjectNode toJSON() { JsonNodeFactory nf = JsonNodeFactory.instance; ObjectNode json = nf.objectNode(); json.put("format", "json"); json.put("entity_type", entityType.getName()); if (!attributes.isEmpty()) { ObjectNode attrNode = json.putObject("attributes"); for (Map.Entry<String,TypedName<?>> attr: attributes.entrySet()) { ObjectNode an = attrNode.putObject(attr.getKey()); an.put("name", attr.getValue().getName()); an.put("type", TypeUtils.makeTypeName(attr.getValue().getType())); } } return json; }
json.put("format", "delimited"); json.put("delimiter", delimiter); json.put("entity_type", entityType.getName()); json.put("base_id", getBaseId()); if (readHeader) {