Geoparsepy inserting new database gives me an error Posted: 24 May 2021 08:40 AM PDT I would like to use more detailed db for geoparsing. my DB has only points enter image description here when I run the script: import soton_corenlppy import geoparsepy import logging import nltk nltk.download('stopwords') logger = logging.getLogger("geoparsepy") logging.basicConfig(level=logging.INFO, format="%(message)s") logger.info('Logging started') geospatial_config = geoparsepy.geo_parse_lib.get_geoparse_config( lang_codes=['it', 'en'], logger=logger ) location_ids = {} location_ids['italia_posti'] = [-1, -1] # Create a connection with the database database_handler = soton_corenlppy.PostgresqlHandler.PostgresqlHandler( user='postgres', passw='password', hostname='localhost', port=5432, database='italia' ) # Load a set of previously preprocessed locations from database cached_locations = geoparsepy.geo_preprocess_lib.cache_preprocessed_locations( database_handle=database_handler, location_ids=location_ids, schema='public', geospatial_config=geospatial_config ) logger.info(f"Loaded {len(cached_locations)} position") # Close connection with the database database_handler.close() # Compile an inverted index from a list of arbirary data where one column is a phrase string indexed_locations = geoparsepy.geo_parse_lib.calc_inverted_index( list_data=cached_locations, dict_geospatial_config=geospatial_config ) logger.info(f"Indexed {len(indexed_locations.keys())} phrases") # Create an index of osmid to row indexes in the cached_locations osmid_lookup = geoparsepy.geo_parse_lib.calc_osmid_lookup(cached_locations=cached_locations) listText = [ u'Io sono di Sciacca, in provincia di agrigento', u'Vengo dalla provincia di Agrigento, in Sicilia', u'Mi sdraio sul prato del mio vicino', u'Pavia e Ravenna sono belle città', u'Voglio andare a new york', u'Mi trovo a San Giuliano Terme', u'Io sono di Sciacca, in provincia di Agrigento', u'Martina vive a Nuoro ma vorrebbe andare ad Agrigento', u'Agrigento è la provincia che contiene il comune di Sciacca', u'Vicino san giuliano terme c\'è un comune che si chiama Asciano', u'La città di Sciacca si trova in provincia di Agrigento', u'Mi trovo a Sciacca' ] listTokenSets = [] for text in listText: # Tokenize a text entry into unigram tokens text will be cleaned and tokenize listToken = soton_corenlppy.common_parse_lib.unigram_tokenize_text( text=text, dict_common_config=geospatial_config ) listTokenSets.append(listToken) # Geoparse token sets using a set of cached locations listMatchSet = geoparsepy.geo_parse_lib.geoparse_token_set( token_set=listTokenSets, dict_inverted_index=indexed_locations, dict_geospatial_config=geospatial_config ) # Print the matched location for i in range(len(listMatchSet)): logger.info(f"\nText: {listText[i]}") listMatch = listMatchSet[i] for tupleMatch in listMatch: logger.info(str(tupleMatch)) I get the following error: <ipython-input-17-c67b3eda95f5> in <module> 34 35 # Load a set of previously preprocessed locations from database ---> 36 cached_locations = geoparsepy.geo_preprocess_lib.cache_preprocessed_locations( 37 database_handle=database_handler, 38 location_ids=location_ids, c:\users\katarina\appdata\local\programs\python\python38\lib\site-packages\geoparsepy\geo_preprocess_lib.py in cache_preprocessed_locations(database_handle, location_ids, schema, geospatial_config, timeout_statement, timeout_overall, spatial_filter) 1647 1648 # note: SQL returns UTF8 encoded <str> objects. to get <unicode> use unicode( strText, 'utf8' ) -> 1649 listRows = database_handle.execute_sql_query_batch( listSQL, timeout_statement, timeout_overall ) 1650 1651 listResult = [] c:\users\katarina\appdata\local\programs\python\python38\lib\site-packages\soton_corenlppy\PostgresqlHandler.py in execute_sql_query_batch(self, query_list, timeout_statement, timeout_overall) 346 347 # failure --> 348 raise Exception( 'SQL query failed (timeout retrying) : ' + strLastError + ' : ' + tupleStatement[0] ) 349 350 def execute_sql_statement( self, statement_list, timeout_statement = 60, timeout_overall = 180 ) : Exception: SQL query failed (timeout retrying) : ['42883'] UndefinedFunction('function hstore_to_matrix(character varying) does not exist\nLINE 1: ...id),name,osm_id_set,admin_regions,ST_AsText(geom),hstore_to_...\n ^\nHINT: No function matches the given name and argument types. You might need to add explicit type casts.\n') : SELECT concat('italia_posti_',loc_id),name,osm_id_set,admin_regions,ST_AsText(geom),hstore_to_matrix(tags) FROM public.italia_posti The original code has db tables that line and polygon that are empty, can it be a problem? I also have two columns more in my point table and admin_regions is empty column. |
Export/Import const function with return res inside Posted: 24 May 2021 08:40 AM PDT I'm struggling with a little function that I can't generalize. const response = (status, value, message) => { return res.status(status).json({ error: value, data: message ? message : null, }) } if I put inside the exports.endpointName = async (req,res) => {} the function and the call function works properly (half working). But I would like to have this function inside a global.js functions file and import it and call it as many times as need it. Any clue of how do it?? I already try some ways as a function exports o exports.response, but no success. |
Testing react components with jest, confused Posted: 24 May 2021 08:40 AM PDT I'm trying to create tests for some basic react components, i'm more used to writing backend tests too be honest, and I'm very confused about how to implement a simple test for if a query through a form to an api is working. Following a tutorial I am trying to just start out with this, // Link.react.test.js import React from 'react'; import renderer from 'react-test-renderer'; import AuthModal from './AuthModal'; test('Link changes the class when hovered', () => { const component = renderer.create( <AuthModal />, ); let tree = component.toJSON(); expect(tree).toMatchSnapshot(); // manually trigger the callback tree.props.onMouseEnter(); // re-rendering tree = component.toJSON(); expect(tree).toMatchSnapshot(); // manually trigger the callback tree.props.onMouseLeave(); // re-rendering tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); onto this component /* This example requires Tailwind CSS v2.0+ */ import { Fragment, useState } from "react"; import { Dialog, Transition } from "@headlessui/react"; import FormAlert from "./FormAlert.js"; import { LockClosedIcon } from "@heroicons/react/solid"; import { XCircleIcon } from '@heroicons/react/solid' import { useForm } from "react-hook-form"; // import { useRouter } from "next/router"; // import AuthForm from "./AuthForm.js" export default function AuthModal() { const [open, setOpen] = useState(false); const [pending, setPending] = useState(false); // const { handleSubmit, register, errors, getValues } = useForm(); const [user, setUser] = useState({ name: "Sign Up!" }); const [formAlert, setFormAlert] = useState(null); console.log(user); // Handle form submission const submit = (e) => { setPending(true); console.log({ name: user.name, email: user.email }); const payload = JSON.stringify({ email: user["email"], name: user["name"], }); console.log(payload); e.preventDefault(); fetch("https://xxx/fakeAuth", { method: "POST", mode: "no-cors", headers: { "Content-Type": "application/json" }, body: payload, }) .then((res) => res.json()) .then((json) => setUser(json)) .catch((error) => { // Show error alert message console.log(error); setFormAlert({ type: "error", message: "didn't work!" }); }) .finally(() => { // Hide pending indicator setPending(false); }); }; // setUser(name="") return ( <> <button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={() => setOpen(true)} > Signup </button> {open ? ( <Transition.Root show={open} as={Fragment}> <Dialog as="div" static className="fixed z-10 inset-0 overflow-y-auto" open={open} onClose={setOpen} > <div className="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0"> <Transition.Child as={Fragment} enter="ease-out duration-300" enterFrom="opacity-0" enterTo="opacity-100" leave="ease-in duration-200" leaveFrom="opacity-100" leaveTo="opacity-0" > <Dialog.Overlay className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" /> </Transition.Child> {/* This element is to trick the browser into centering the modal contents. */} <span className="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true" > ​ </span> <Transition.Child as={Fragment} enter="ease-out duration-300" enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" enterTo="opacity-100 translate-y-0 sm:scale-100" leave="ease-in duration-200" leaveFrom="opacity-100 translate-y-0 sm:scale-100" leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" > <div className="inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-sm sm:w-full sm:p-6"> <> {formAlert ? ( <FormAlert type={formAlert.type} message={formAlert.message} /> ) : ( <div className=" flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8"> <div className="max-w-md w-full space-y-8"> <div> <img className="mx-auto h-12 w-auto" src="/static/example_photos/fullheaderlogo.png" alt="Workflow" /> <h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900"> Create your account </h2> </div> <form className="mt-8 space-y-6" onSubmit={submit} method="POST" > <input type="hidden" name="remember" defaultValue="true" /> <div className="rounded-md shadow-sm -space-y-px"> <div> <label htmlFor="Name" className="sr-only"> Name </label> <input type="text" name="user[name]" id="name" value={user.name} onChange={(e) => setUser({ ...user, name: e.target.value }) } autoComplete="Name" required className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm" placeholder="Name" /> </div> <div> <label htmlFor="email-address" className="sr-only" > Email address </label> <input id="email" name="user[email]" value={user.email} onChange={(e) => setUser({ ...user, email: e.target.value }) } autoComplete="email" required className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm" placeholder="Email address" /> </div> <div> <label htmlFor="confirm-email" className="sr-only" > Confirm Email address </label> <input id="confirm-email" name="confirmEmail" type="confirmEmail" autoComplete="confirmEmail" required className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm" placeholder="Confirm Email Address" /> </div> </div> <div> <button type="submit" className="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" disabled={pending} onClick={submit} > {!pending && ( <div> {" "} <span className="absolute left-0 inset-y-0 flex items-center pl-3"> <LockClosedIcon className="h-5 w-5 text-indigo-500 group-hover:text-indigo-400" aria-hidden="true" /> </span> Sign Up </div> )} {pending && ( <> <svg className="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" > <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" ></circle> <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" ></path> </svg> <span>Please wait...</span> </> )} </button> </div> </form> </div> </div> )} </>{" "} </div> </Transition.Child> </div> </Dialog> </Transition.Root> ) : null} </> ); } How on earth do I just test that the email validation is working? Confused about how you are meant to just have the inputs be working and hve the form inputs clicked? |
How to count distance between two lines in Python? Posted: 24 May 2021 08:40 AM PDT I started a project on SQLite but I think Python is better suited for doing the necessary calculations. I am now stuck for 5 days due to poor coding skills. Here is a sample of my database with 3 colums : class, year and student_name. I search the "distance" in terms of common student between two given student. (Like in the famous game "Oracle of Bacon") The goal is to calculate the distance between Momo Thary (2018) and Paul Biloux (2020). And the answer is 2 students : Momo Thary was in the same class than Jack Spiral in 2018. Jack Spiral was in the same class than Lucien Lake in 2019. And Lucien Lake was in the same class than Paul Biloux in 2020. Problem solved here : we can "link" Momo Thary and Paul Biloux with 2 students. Distance is 2. The issue is when I try a program to know all the possible paths (with distance < 5 so it is not too long to calculate). I have this code in SQLite that calculate all the possible paths and answer with the shortest : WITH RECURSIVE rec(distance, student_name, path) AS ( -- start with Paul Biloux SELECT 0, 'Paul Biloux', '|Paul Biloux|' UNION -- increment distance SELECT r.distance + 1, l1.student_name, r.path || l1.student_name || '|' FROM rec r JOIN lignes l1 -- avoid loops ON r.path NOT LIKE '%|' || l1.student_name || '|%' -- there is a common class WHERE exists (SELECT * FROM lignes l2 WHERE l2.year = l1.year AND l2.grade = l1.grade AND l2.student_name = r.student_name AND r.distance < 5) ) -- keep only the shortest path -- if there are more than one, choose one randomely -- (this is specific to SQLite) SELECT student_name, MIN(distance) AS dist, path FROM rec WHERE student_name = 'Momo Thary' GROUP BY student_name ORDER BY distance It works because the database is only 9 lines. I have a database with 60 lines and SQL is just giving up when I try to execute this code. And my entire database is about 400k lines so it is impossible to do this with SQL. I am quite stuck for 5 days and I gave up with SQLite. I am looking for a way to "translate" this code into Python, better suited than SQL. Does someone could translate this code into Python ? I read that Python with numpy would be a perfect fit. I can provide my SQL script, the 9-line, 60-line and 400k-line database to anyone skilled in Python to help me. Thank you in advance for possible answers ! |
Beautiful soup gives output as "Searching for your content..." when trying to get main article text Posted: 24 May 2021 08:39 AM PDT I'm trying to extract the main article text from some pages on newswire website using beautiful soup. But instead of the text output. I get an output that says "Searching for your content..." I would highly appreciate any help. I seem to be doing something fundamentally wrong here. (I'm sorry about that, if I'm doing it the wrong way as I'm a beginner in coding) from bs4 import BeautifulSoup from urllib.request import Request, urlopen site= "https://www.newswire.ca/news-releases/rbc-capital-markets-launches-aiden-r-a-new-ai-powered-electronic-trading-platform-891623791.html" hdr = {'User-Agent': 'Mozilla/5.0'} req = Request(site,headers=hdr) page = urlopen(req) soup = BeautifulSoup(page) text = soup.find_all('p', {"class":"text-muted"})[0].text.strip() print(text) |
How to send SMS using telephony in case of DUAL SIM in Flutter Posted: 24 May 2021 08:39 AM PDT I am using telephony package to send SMS in Flutter, but I have two SIMS. And for one SIM I have balance and one has not. It is only sending SMS by default i.e using SIM 1 but I want is that the app should send SMS using SIM 2. But I am unable to send a message using the SIMs, it is sending by default telephony package: telephony: ^0.1.4 Code: final Telephony telephony = Telephony.instance; void sendSMS(String number) async { print(number); // Check if a device is capable of sending SMS bool canSendSms = await telephony.isSmsCapable; print(canSendSms); // Get sim state SimState simState = await telephony.simState; print(simState); telephony.sendSms( to: number, message: "Hey i am having Epilepsy Attack XD",); } Please help me out how can i change which SIM to send a message on Flutter App |
Angular - Cannot GET / error after importing a module in app.module.ts file Posted: 24 May 2021 08:39 AM PDT Using the below link i am trying to create a web page in Angular with same kind of functionality , as mentioned in the link i have executed the command $ npm install --save ngx-plaid-link using Git bash https://www.mikeroberts.engineer/blog/2018-08-16/introducing-ngx-plaid-link I am following step by step mentioned in the above link, when i imported import { NgxPlaidLinkModule } from 'ngx-plaid-link'; in my app.module.ts file and run the application i am seeing an error in the browser. Cannot GET / When i comment the line import { NgxPlaidLinkModule } from 'ngx-plaid-link'; in the app.module.ts , then the application is loading fine.. but i need NgxPlaidLinkModule in my application. What could be the reasons for this, any help on this ? |
openGL 4, trying to use painter's method and failing Posted: 24 May 2021 08:39 AM PDT I'm just learning openGL, and There's a lot I don't understand, so be gentle. I'm likely doing something foolish. I'm drawing a floor plan. It's a ortho projection. In the rendering callback, first I paint the floor (z=0) with a pattern, and for the moment I'm filling the whole screen with that pattern. All good. Now it's time to paint the walls, which are just just a lot of skinny rectangles cut into triangles, because apparently drawing thick lines is supposed to be that way. Originally I did both floor and walls with one fragment shader. I'd draw the floor triangles, set a flag for the shader to see, and then draw the skinny wall triangles. The fragment shader honored the flag by using a different color, and I got floors and walls atop drawn to my satisfaction. But as I add features I'm going to have more and more things to draw over the floor, so I decided to break the fragment shader apart - one for floors, one for walls, and there will be others for other features. I call glUSeProgram() for the floor, draw my triangles, then call glUseProgram() [and here be dragons it seems] to set the wall shaders up and draw the walls (at z=0.5, just to be sure). Everything broke, and in an interesting way: if I comment out the 2nd glUseProgram and associated draws, I can see the floor. If I put the 2nd Use and Draw ops back in, I see only the walls. And if I draw walls but no-op the wall shader (void main() {return;}) I get nothing drawn at all. With testing I determined that just calling the 2nd glUSeProgram() does the damage. Even if I draw no walls and have a no-op fragment shader after that, the floor is gone and window is blank. So it's not the wall fragment shader going off the rails. I have a wild theory. I'm guessing this is all asynchronous, and the 2nd UseProgram blows away whatever is in progress with the first one (maybe nothing has even started drawing yet?) If that's true I need some way to say "ok, wait for the first program to finish everywhere". If that's false, I'm at a total loss because I don't see anything that suggests the glUSeProgram() is going to wipe the slate. Where did I go wrong? I could in theory do everything in one fragment shader, but it would be immense and I know you aren't supposed to need to do that. Here's the code in the render callback; the #if 01 just indicates what I switch off and on to try things. glBindFramebuffer(GL_FRAMEBUFFER, 0); glClear(GL_COLOR_BUFFER_BIT); //start clean mapData.selectShader(mapData.programDMFloor); //does glUseProgram (see below) glEnableVertexAttribArray(0); //needed, no idea why? glBindBuffer(GL_ARRAY_BUFFER, VBOS); //2 triangles (that for now cover the window) glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); //indexed draw for these glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); //paint the window with the floor glDisableVertexAttribArray(0); //needed, no idea why? //If we stop here, we see the floor pattern as expected. But..! #if 01 mapData.selectShader(mapData.programDMWall); //The floor is now gone (or maybe never happened) //this draws the walls glEnableVertexAttribArray(0); //needed, don't know why glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); //no indexed draw for these glBindBuffer(GL_ARRAY_BUFFER, mapData.wallBuffer_); //Select a lot of skinny triangles glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); //std::cout << "Wall draw " << mapData.triangles_.size() * 3 << " floats from buf " << mapData.wallBuffer_ << '\n'; glDrawArrays(GL_TRIANGLES, 0, mapData.triangles_.size() * 3); //no indexed draw for this one glDisableVertexAttribArray(0); //we see the walls, but no floor! #else //we see the floor, and of course no walls. //Need both!
|
No comments:
Post a Comment