@Test public void testPhoneNumberExtraction() throws Exception { InputStream in = asStream(PHONE_TEXT); VertexBuilder vertexBuilder = graph.prepareVertex("v1", visibility); StreamingPropertyValue textPropertyValue = new StreamingPropertyValue(in, String.class); LumifyProperties.TEXT.setProperty(vertexBuilder, textPropertyValue, visibility); LumifyProperties.VISIBILITY_JSON.setProperty(vertexBuilder, visibilityJson, visibility); Vertex vertex = vertexBuilder.save(authorizations); Property property = vertex.getProperty(LumifyProperties.TEXT.getPropertyName()); GraphPropertyWorkData workData = new GraphPropertyWorkData(visibilityTranslator, vertex, property, null, null); in = asStream(PHONE_TEXT); extractor.execute(in, workData); List<Vertex> termMentions = toList(vertex.getVertices(Direction.OUT, LumifyProperties.TERM_MENTION_LABEL_HAS_TERM_MENTION, authorizations)); assertEquals("Incorrect number of phone numbers extracted", 2, termMentions.size()); boolean foundFirst = false; boolean foundSecond = false; for (Vertex term : termMentions) { String title = LumifyProperties.TERM_MENTION_TITLE.getPropertyValue(term); if (title.equals("+14106782230")) { foundFirst = true; assertEquals(33, LumifyProperties.TERM_MENTION_START_OFFSET.getPropertyValue(term, 0)); assertEquals(45, LumifyProperties.TERM_MENTION_END_OFFSET.getPropertyValue(term, 0)); } else if (title.equals("+442074370478")) { foundSecond = true; assertEquals(84, LumifyProperties.TERM_MENTION_START_OFFSET.getPropertyValue(term, 0)); assertEquals(103, LumifyProperties.TERM_MENTION_END_OFFSET.getPropertyValue(term, 0)); } } assertTrue("+14106782230 not found", foundFirst); assertTrue("+442074370478 not found", foundSecond); }
@Override public void execute(InputStream in, GraphPropertyWorkData data) throws Exception { LOGGER.debug("Extracting phone numbers from provided text"); final String text = CharStreams.toString(new InputStreamReader(in, Charsets.UTF_8)); Vertex sourceVertex = (Vertex) data.getElement(); VisibilityJson visibilityJson = LumifyProperties.VISIBILITY_JSON.getPropertyValue(sourceVertex); final Iterable<PhoneNumberMatch> phoneNumbers = phoneNumberUtil.findNumbers(text, defaultRegionCode); List<Vertex> termMentions = new ArrayList<>(); for (final PhoneNumberMatch phoneNumber : phoneNumbers) { final String formattedNumber = phoneNumberUtil.format(phoneNumber.number(), PhoneNumberUtil.PhoneNumberFormat.E164); int start = phoneNumber.start(); int end = phoneNumber.end(); Vertex termMention = new TermMentionBuilder() .sourceVertex(sourceVertex) .propertyKey(data.getProperty().getKey()) .start(start) .end(end) .title(formattedNumber) .conceptIri(entityType) .visibilityJson(visibilityJson) .process(getClass().getName()) .save(getGraph(), getVisibilityTranslator(), getAuthorizations()); termMentions.add(termMention); } getGraph().flush(); applyTermMentionFilters(sourceVertex, termMentions); pushTextUpdated(data); LOGGER.debug("Number of phone numbers extracted: %d", count(phoneNumbers)); }
PhoneNumberGraphPropertyWorker extends GraphPropertyWorker { @Override public void execute(InputStream in, GraphPropertyWorkData data) throws Exception { LOGGER.debug("Extracting phone numbers from provided text"); final String text = CharStreams.toString(new InputStreamReader(in, Charsets.UTF_8)); Vertex sourceVertex = (Vertex) data.getElement(); VisibilityJson visibilityJson = LumifyProperties.VISIBILITY_JSON.getPropertyValue(sourceVertex); final Iterable<PhoneNumberMatch> phoneNumbers = phoneNumberUtil.findNumbers(text, defaultRegionCode); List<Vertex> termMentions = new ArrayList<>(); for (final PhoneNumberMatch phoneNumber : phoneNumbers) { final String formattedNumber = phoneNumberUtil.format(phoneNumber.number(), PhoneNumberUtil.PhoneNumberFormat.E164); int start = phoneNumber.start(); int end = phoneNumber.end(); Vertex termMention = new TermMentionBuilder() .sourceVertex(sourceVertex) .propertyKey(data.getProperty().getKey()) .start(start) .end(end) .title(formattedNumber) .conceptIri(entityType) .visibilityJson(visibilityJson) .process(getClass().getName()) .save(getGraph(), getVisibilityTranslator(), getAuthorizations()); termMentions.add(termMention); } getGraph().flush(); applyTermMentionFilters(sourceVertex, termMentions); pushTextUpdated(data); LOGGER.debug("Number of phone numbers extracted: %d", count(phoneNumbers)); } }
PhoneNumberGraphPropertyWorker extends GraphPropertyWorker { @Override public void execute(InputStream in, GraphPropertyWorkData data) throws Exception { LOGGER.debug("Extracting phone numbers from provided text"); final String text = CharStreams.toString(new InputStreamReader(in, Charsets.UTF_8)); Vertex sourceVertex = (Vertex) data.getElement(); VisibilityJson visibilityJson = LumifyProperties.VISIBILITY_JSON.getPropertyValue(sourceVertex); final Iterable<PhoneNumberMatch> phoneNumbers = phoneNumberUtil.findNumbers(text, defaultRegionCode); List<Vertex> termMentions = new ArrayList<>(); for (final PhoneNumberMatch phoneNumber : phoneNumbers) { final String formattedNumber = phoneNumberUtil.format(phoneNumber.number(), PhoneNumberUtil.PhoneNumberFormat.E164); int start = phoneNumber.start(); int end = phoneNumber.end(); Vertex termMention = new TermMentionBuilder() .sourceVertex(sourceVertex) .propertyKey(data.getProperty().getKey()) .start(start) .end(end) .title(formattedNumber) .conceptIri(entityType) .visibilityJson(visibilityJson) .process(getClass().getName()) .save(getGraph(), getVisibilityTranslator(), getAuthorizations()); termMentions.add(termMention); } getGraph().flush(); applyTermMentionFilters(sourceVertex, termMentions); pushTextUpdated(data); LOGGER.debug("Number of phone numbers extracted: %d", count(phoneNumbers)); }  }
PhoneNumberGraphPropertyWorker extends GraphPropertyWorker { @Override public void execute(InputStream in, GraphPropertyWorkData data) throws Exception { LOGGER.debug("Extracting phone numbers from provided text"); final String text = CharStreams.toString(new InputStreamReader(in, Charsets.UTF_8)); Vertex sourceVertex = (Vertex) data.getElement(); VisibilityJson visibilityJson = LumifyProperties.VISIBILITY_JSON.getPropertyValue(sourceVertex); final Iterable<PhoneNumberMatch> phoneNumbers = phoneNumberUtil.findNumbers(text, defaultRegionCode); List<Vertex> termMentions = new ArrayList<>(); for (final PhoneNumberMatch phoneNumber : phoneNumbers) { final String formattedNumber = phoneNumberUtil.format(phoneNumber.number(), PhoneNumberUtil.PhoneNumberFormat.E164); int start = phoneNumber.start(); int end = phoneNumber.end(); Vertex termMention = new TermMentionBuilder() .sourceVertex(sourceVertex) .propertyKey(data.getProperty().getKey()) .start(start) .end(end) .title(formattedNumber) .conceptIri(entityType) .visibilityJson(visibilityJson) .process(getClass().getName()) .save(getGraph(), getVisibilityTranslator(), getAuthorizations()); termMentions.add(termMention); } getGraph().flush(); applyTermMentionFilters(sourceVertex, termMentions); pushTextUpdated(data); LOGGER.debug("Number of phone numbers extracted: %d", count(phoneNumbers)); }  @Override void prepare(GraphPropertyWorkerPrepareData workerPrepareData); @Override void execute(InputStream in, GraphPropertyWorkData data); @Override boolean isHandled(Element element, Property property); }
PhoneNumberGraphPropertyWorker extends GraphPropertyWorker { @Override public void execute(InputStream in, GraphPropertyWorkData data) throws Exception { LOGGER.debug("Extracting phone numbers from provided text"); final String text = CharStreams.toString(new InputStreamReader(in, Charsets.UTF_8)); Vertex sourceVertex = (Vertex) data.getElement(); VisibilityJson visibilityJson = LumifyProperties.VISIBILITY_JSON.getPropertyValue(sourceVertex); final Iterable<PhoneNumberMatch> phoneNumbers = phoneNumberUtil.findNumbers(text, defaultRegionCode); List<Vertex> termMentions = new ArrayList<>(); for (final PhoneNumberMatch phoneNumber : phoneNumbers) { final String formattedNumber = phoneNumberUtil.format(phoneNumber.number(), PhoneNumberUtil.PhoneNumberFormat.E164); int start = phoneNumber.start(); int end = phoneNumber.end(); Vertex termMention = new TermMentionBuilder() .sourceVertex(sourceVertex) .propertyKey(data.getProperty().getKey()) .start(start) .end(end) .title(formattedNumber) .conceptIri(entityType) .visibilityJson(visibilityJson) .process(getClass().getName()) .save(getGraph(), getVisibilityTranslator(), getAuthorizations()); termMentions.add(termMention); } getGraph().flush(); applyTermMentionFilters(sourceVertex, termMentions); pushTextUpdated(data); LOGGER.debug("Number of phone numbers extracted: %d", count(phoneNumbers)); }  @Override void prepare(GraphPropertyWorkerPrepareData workerPrepareData); @Override void execute(InputStream in, GraphPropertyWorkData data); @Override boolean isHandled(Element element, Property property); static final String DEFAULT_REGION_CODE; static final String DEFAULT_DEFAULT_REGION_CODE; }