Fixes to entity extraction
This commit is contained in:
parent
195d2f7d2b
commit
0296e8411e
5 changed files with 83 additions and 37 deletions
|
@ -6,14 +6,9 @@
|
|||
// import {ReactNativeStore} from './auth'
|
||||
import AdxApi from '../../third-party/api'
|
||||
import {ServiceClient} from '../../third-party/api/src/index'
|
||||
import {
|
||||
TextSlice,
|
||||
Entity as Entities,
|
||||
} from '../../third-party/api/src/types/todo/social/post'
|
||||
import {AdxUri} from '../../third-party/uri'
|
||||
import {RootStoreModel} from '../models/root-store'
|
||||
|
||||
type Entity = Entities[0]
|
||||
import {extractEntities} from '../../view/lib/strings'
|
||||
|
||||
export function doPolyfill() {
|
||||
AdxApi.xrpc.fetch = fetchHandler
|
||||
|
@ -204,20 +199,3 @@ async function iterateAll(
|
|||
}
|
||||
} while (res.records.length === 100)
|
||||
}*/
|
||||
|
||||
function extractEntities(text: string): Entity[] | undefined {
|
||||
let match
|
||||
let ents: Entity[] = []
|
||||
const re = /(^|\s)@([a-zA-Z0-9\.-]+)(\b)/g
|
||||
while ((match = re.exec(text))) {
|
||||
ents.push({
|
||||
type: 'mention',
|
||||
value: match[2],
|
||||
index: [
|
||||
match.index + 1, // skip the (^|\s) but include the '@'
|
||||
match.index + 2 + match[2].length,
|
||||
],
|
||||
})
|
||||
}
|
||||
return ents.length > 0 ? ents : undefined
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import React, {useMemo, useState} from 'react'
|
||||
import React, {useEffect, useMemo, useState} from 'react'
|
||||
import {StyleSheet, Text, TouchableOpacity, View} from 'react-native'
|
||||
import {BottomSheetTextInput} from '@gorhom/bottom-sheet'
|
||||
import LinearGradient from 'react-native-linear-gradient'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import * as GetUserFollows from '../../../third-party/api/src/types/todo/social/getUserFollows'
|
||||
import {Autocomplete} from './composer/Autocomplete'
|
||||
import Toast from '../util/Toast'
|
||||
import ProgressCircle from '../util/ProgressCircle'
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import {AdxUri} from '../../third-party/uri'
|
||||
import {Entity as Entities} from '../../third-party/api/src/types/todo/social/post'
|
||||
|
||||
type Entity = Entities[0]
|
||||
|
||||
export function pluralize(n: number, base: string, plural?: string): string {
|
||||
if (n === 1) {
|
||||
|
@ -53,3 +56,20 @@ export function ago(date: number | string | Date): string {
|
|||
return new Date(ts).toLocaleDateString()
|
||||
}
|
||||
}
|
||||
|
||||
export function extractEntities(text: string): Entity[] | undefined {
|
||||
let match
|
||||
let ents: Entity[] = []
|
||||
const re = /(^|\s)(@)([a-zA-Z0-9\.-]+)(\b)/dg
|
||||
while ((match = re.exec(text))) {
|
||||
ents.push({
|
||||
type: 'mention',
|
||||
value: match[3],
|
||||
index: [
|
||||
match.indices[2][0], // skip the (^|\s) but include the '@'
|
||||
match.indices[3][1],
|
||||
],
|
||||
})
|
||||
}
|
||||
return ents.length > 0 ? ents : undefined
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue